summaryrefslogtreecommitdiff
path: root/src/SSVOpenHexagon/Global/Config.cpp
blob: ecdf0d69e13385dbde6cc316ffad907c05cd2037 (plain)
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
// Copyright (c) 2013-2020 Vittorio Romeo
// License: Academic Free License ("AFL") v. 3.0
// AFL License page: http://opensource.org/licenses/AFL-3.0

#include "SSVOpenHexagon/Global/Config.hpp"
#include "SSVOpenHexagon/Global/Assets.hpp"
#include "SSVOpenHexagon/Utils/Utils.hpp"
#include "SSVOpenHexagon/Online/Online.hpp"
#include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp"

#include <SSVStart/Input/Input.hpp>
#include <SSVStart/GameSystem/GameWindow.hpp>

#include <iostream>
#include <fstream>
#include <memory>

using namespace std;
using namespace sf;
using namespace ssvs;
using namespace ssvs::Input;
using namespace ssvu::FileSystem;
using namespace ssvuj;
using namespace ssvu;

#define X_LINKEDVALUES                                                     \
    X(online, bool, "online")                                              \
    X(official, bool, "official")                                          \
    X(noRotation, bool, "no_rotation")                                     \
    X(noBackground, bool, "no_background")                                 \
    X(noSound, bool, "no_sound")                                           \
    X(noMusic, bool, "no_music")                                           \
    X(blackAndWhite, bool, "black_and_white")                              \
    X(pulseEnabled, bool, "pulse_enabled")                                 \
    X(_3DEnabled, bool, "3D_enabled")                                      \
    X(_3DMultiplier, float, "3D_multiplier")                               \
    X(_3DMaxDepth, unsigned int, "3D_max_depth")                           \
    X(invincible, bool, "invincible")                                      \
    X(autoRestart, bool, "auto_restart")                                   \
    X(soundVolume, float, "sound_volume")                                  \
    X(musicVolume, float, "music_volume")                                  \
    X(flashEnabled, bool, "flash_enabled")                                 \
    X(zoomFactor, float, "zoom_factor")                                    \
    X(pixelMultiplier, int, "pixel_multiplier")                            \
    X(playerSpeed, float, "player_speed")                                  \
    X(playerFocusSpeed, float, "player_focus_speed")                       \
    X(playerSize, float, "player_size")                                    \
    X(limitFPS, bool, "limit_fps")                                         \
    X(vsync, bool, "vsync")                                                \
    X(autoZoomFactor, bool, "auto_zoom_factor")                            \
    X(fullscreen, bool, "fullscreen")                                      \
    X(windowedAutoResolution, bool, "windowed_auto_resolution")            \
    X(fullscreenAutoResolution, bool, "fullscreen_auto_resolution")        \
    X(fullscreenWidth, unsigned int, "fullscreen_width")                   \
    X(fullscreenHeight, unsigned int, "fullscreen_height")                 \
    X(windowedWidth, unsigned int, "windowed_width")                       \
    X(windowedHeight, unsigned int, "windowed_height")                     \
    X(showMessages, bool, "show_messages")                                 \
    X(debug, bool, "debug")                                                \
    X(beatPulse, bool, "beatpulse_enabled")                                \
    X(showTrackedVariables, bool, "show_tracked_variables")                \
    X(musicSpeedDMSync, bool, "music_speed_dm_sync")                       \
    X(maxFPS, unsigned int, "max_fps")                                     \
    X(antialiasingLevel, unsigned int, "antialiasing_level")               \
    X(showFPS, bool, "show_fps")                                           \
    X(timerStatic, bool, "timer_static")                                   \
    X(serverLocal, bool, "server_local")                                   \
    X(serverVerbose, bool, "server_verbose")                               \
    X(mouseVisible, bool, "mouse_visible")                                 \
    X(musicSpeedMult, float, "music_speed_mult")                           \
    X(drawTextOutlines, bool, "draw_text_outlines")                        \
    X(darkenUnevenBackgroundChunk, bool, "darken_uneven_background_chunk") \
    X(rotateToStart, bool, "rotate_to_start")                              \
    X(joystickDeadzone, float, "joystick_deadzone")                        \
    X(textPadding, float, "text_padding")                                  \
    X(textScaling, float, "text_scaling")                                  \
    X(triggerRotateCCW, Trigger, "t_rotate_ccw")                           \
    X(triggerRotateCW, Trigger, "t_rotate_cw")                             \
    X(triggerFocus, Trigger, "t_focus")                                    \
    X(triggerExit, Trigger, "t_exit")                                      \
    X(triggerForceRestart, Trigger, "t_force_restart")                     \
    X(triggerRestart, Trigger, "t_restart")                                \
    X(triggerScreenshot, Trigger, "t_screenshot")                          \
    X(triggerSwap, Trigger, "t_swap")                                      \
    X(triggerUp, Trigger, "t_up")                                          \
    X(triggerDown, Trigger, "t_down")

namespace hg::Config
{

[[nodiscard]] static ssvuj::Obj& root() noexcept
{
    static auto res = getFromFile("config.json");
    return res;
}

#define X(name, type, key)                                 \
    [[nodiscard]] static auto& name() noexcept             \
    {                                                      \
        static auto res = ::ssvuj::LinkedValue<type>(key); \
        return res;                                        \
    }
X_LINKEDVALUES
#undef X

static void syncAllFromObj()
{
#define X(name, type, key) name().syncFrom(root());
    X_LINKEDVALUES
#undef X
}

static void syncAllToObj()
{
#define X(name, type, key) name().syncTo(root());
    X_LINKEDVALUES
#undef X
}

float sizeX{1500}, sizeY{1500};
constexpr float spawnDistance{1600};
string uneligibilityReason;

void applyAutoWindowedResolution()
{
    auto d(VideoMode::getDesktopMode());
    windowedWidth() = d.width;
    windowedHeight() = d.height;
}
void applyAutoFullscreenResolution()
{
    auto d(VideoMode::getDesktopMode());
    fullscreenWidth() = d.width;
    fullscreenHeight() = d.height;
}

void loadConfig(const vector<string>& mOverridesIds)
{
    lo("::loadConfig") << "loading config\n";

    for(const auto p :
        getScan<ssvufs::Mode::Single, ssvufs::Type::File, ssvufs::Pick::ByExt>(
            "ConfigOverrides/", ".json"))
    {
        if(contains(mOverridesIds, p.getFileNameNoExtensions()))
        {
            const auto overrideRoot(getFromFile(p));
            for(auto itr(begin(overrideRoot)); itr != end(overrideRoot); ++itr)
            {
                root()[getKey(itr)] = *itr;
            }
        }
    }

    syncAllFromObj();

    if(getWindowedAutoResolution())
    {
        applyAutoWindowedResolution();
    }

    if(getFullscreenAutoResolution())
    {
        applyAutoFullscreenResolution();
    }

    recalculateSizes();
}

void saveConfig()
{
    lo("::saveConfig") << "saving config\n";
    syncAllToObj();
    writeToFile(root(), "config.json");
}

bool isEligibleForScore()
{
    if(!getOfficial())
    {
        uneligibilityReason = "official mode off";
        return false;
    }

    if(getDebug())
    {
        uneligibilityReason = "debug mode on";
        return false;
    }

    if(!getAutoZoomFactor())
    {
        uneligibilityReason = "modified zoom factor";
        return false;
    }

    if(getPlayerSpeed() != 9.45f)
    {
        uneligibilityReason = "player speed modified";
        return false;
    }

    if(getPlayerFocusSpeed() != 4.625f)
    {
        uneligibilityReason = "player focus speed modified";
        return false;
    }

    if(getPlayerSize() != 7.3f)
    {
        uneligibilityReason = "player size modified";
        return false;
    }

    if(getInvincible())
    {
        uneligibilityReason = "invincibility on";
        return false;
    }

    if(getNoRotation())
    {
        uneligibilityReason = "rotation off";
        return false;
    }

    if(Online::getServerVersion() == -1)
    {
        uneligibilityReason = "connection error";
        return false;
    }

    if(Online::getServerVersion() > getVersion())
    {
        uneligibilityReason = "version mismatch";
        return false;
    }

    return true;
}

void recalculateSizes()
{
    sizeX = sizeY = max(getWidth(), getHeight()) * 1.3f;
    if(!getAutoZoomFactor())
    {
        return;
    }

    const float factorX(1024.f / ssvu::toFloat(getWidth()));
    const float factorY(768.f / ssvu::toFloat(getHeight()));
    zoomFactor() = max(factorX, factorY);
}
void setFullscreen(GameWindow& mWindow, bool mFullscreen)
{
    fullscreen() = mFullscreen;

    mWindow.setSize(getWidth(), getHeight());
    mWindow.setFullscreen(getFullscreen());
    mWindow.setMouseCursorVisible(Config::getMouseVisible());

    recalculateSizes();
}

void refreshWindowSize(unsigned int mWidth, unsigned int mHeight)
{
    windowedWidth() = mWidth;
    windowedHeight() = mHeight;
}

void setCurrentResolution(
    GameWindow& mWindow, unsigned int mWidth, unsigned int mHeight)
{
    if(fullscreen())
    {
        fullscreenAutoResolution() = false;
        fullscreenWidth() = mWidth;
        fullscreenHeight() = mHeight;
    }
    else
    {
        windowedAutoResolution() = false;
        windowedWidth() = mWidth;
        windowedHeight() = mHeight;
    }

    mWindow.setSize(getWidth(), getHeight());
    mWindow.setFullscreen(getFullscreen());
    mWindow.setMouseCursorVisible(Config::getMouseVisible());
    recalculateSizes();
}
void setCurrentResolutionAuto(GameWindow& mWindow)
{
    if(fullscreen())
    {
        fullscreenAutoResolution() = true;
        applyAutoFullscreenResolution();
    }
    else
    {
        windowedAutoResolution() = true;
        applyAutoWindowedResolution();
    }

    mWindow.setSize(getWidth(), getHeight());
    mWindow.setFullscreen(getFullscreen());
    mWindow.setMouseCursorVisible(Config::getMouseVisible());
    recalculateSizes();
}
void setVsync(GameWindow& mWindow, bool mValue)
{
    vsync() = mValue;
    mWindow.setVsync(vsync());
}
void setLimitFPS(GameWindow& mWindow, bool mValue)
{
    limitFPS() = mValue;
    mWindow.setFPSLimited(mValue);
}
void setMaxFPS(GameWindow& mWindow, unsigned int mValue)
{
    maxFPS() = mValue;
    mWindow.setMaxFPS(mValue);
}
void setTimerStatic(GameWindow& mWindow, bool mValue)
{
    timerStatic() = mValue;

    if(timerStatic())
    {
        mWindow.setTimer<TimerStatic>(0.5f, 0.5f);
    }
    else
    {
        mWindow.setTimer<TimerDynamic>();
        setLimitFPS(mWindow, true);
        setMaxFPS(mWindow, 200);
    }
}

void setAntialiasingLevel(GameWindow& mWindow, unsigned int mValue)
{
    antialiasingLevel() = mValue;
    mWindow.setAntialiasingLevel(mValue);
}

void setOnline(bool mOnline)
{
    online() = mOnline;
}

void setOfficial(bool mOfficial)
{
    official() = mOfficial;
}

void setDebug(bool mDebug)
{
    debug() = mDebug;
}

void setNoRotation(bool mNoRotation)
{
    noRotation() = mNoRotation;
}

void setNoBackground(bool mNoBackground)
{
    noBackground() = mNoBackground;
}

void setBlackAndWhite(bool mBlackAndWhite)
{
    blackAndWhite() = mBlackAndWhite;
}

void setNoSound(bool mNoSound)
{
    noSound() = mNoSound;
}

void setNoMusic(bool mNoMusic)
{
    noMusic() = mNoMusic;
}

void setPulse(bool mPulse)
{
    pulseEnabled() = mPulse;
}

void set3D(bool m3D)
{
    _3DEnabled() = m3D;
}

void setInvincible(bool mInvincible)
{
    invincible() = mInvincible;
}

void setAutoRestart(bool mAutoRestart)
{
    autoRestart() = mAutoRestart;
}

void setSoundVolume(float mVolume)
{
    soundVolume() = mVolume;
}

void setMusicVolume(float mVolume)
{
    musicVolume() = mVolume;
}

void setFlash(bool mFlash)
{
    flashEnabled() = mFlash;
}

void setMusicSpeedDMSync(bool mValue)
{
    musicSpeedDMSync() = mValue;
}

void setShowFPS(bool mValue)
{
    showFPS() = mValue;
}

void setServerLocal(bool mValue)
{
    serverLocal() = mValue;
}

void setServerVerbose(bool mValue)
{
    serverVerbose() = mValue;
}

void setMouseVisible(bool mValue)
{
    mouseVisible() = mValue;
}

void setMusicSpeedMult(float mValue)
{
    musicSpeedMult() = mValue;
}

void setDrawTextOutlines(bool mX)
{
    drawTextOutlines() = mX;
}

void setDarkenUnevenBackgroundChunk(bool mX)
{
    darkenUnevenBackgroundChunk() = mX;
}

void setRotateToStart(bool mX)
{
    rotateToStart() = mX;
}

void setJoystickDeadzone(float mX)
{
    joystickDeadzone() = mX;
}

void setTextPadding(float mX)
{
    textPadding() = mX;
}

void setTextScaling(float mX)
{
    textScaling() = mX;
}

bool SSVU_ATTRIBUTE(pure) getOnline()
{
    return online();
}

bool SSVU_ATTRIBUTE(pure) getOfficial()
{
    return official();
}

string SSVU_ATTRIBUTE(pure) getUneligibilityReason()
{
    return uneligibilityReason;
}

float SSVU_ATTRIBUTE(pure) getSizeX()
{
    return sizeX;
}

float SSVU_ATTRIBUTE(pure) getSizeY()
{
    return sizeY;
}

float SSVU_ATTRIBUTE(const) getSpawnDistance()
{
    return spawnDistance;
}

float SSVU_ATTRIBUTE(pure) getZoomFactor()
{
    return zoomFactor();
}

int SSVU_ATTRIBUTE(pure) getPixelMultiplier()
{
    return pixelMultiplier();
}

float SSVU_ATTRIBUTE(pure) getPlayerSpeed()
{
    return getOfficial() ? 9.45f : playerSpeed();
}

float SSVU_ATTRIBUTE(pure) getPlayerFocusSpeed()
{
    return getOfficial() ? 4.625f : playerFocusSpeed();
}

float SSVU_ATTRIBUTE(pure) getPlayerSize()
{
    return getOfficial() ? 7.3f : playerSize();
}

bool SSVU_ATTRIBUTE(pure) getNoRotation()
{
    return getOfficial() ? false : noRotation();
}

bool SSVU_ATTRIBUTE(pure) getNoBackground()
{
    return getOfficial() ? false : noBackground();
}

bool SSVU_ATTRIBUTE(pure) getBlackAndWhite()
{
    return getOfficial() ? false : blackAndWhite();
}

bool SSVU_ATTRIBUTE(pure) getNoSound()
{
    return noSound();
}

bool SSVU_ATTRIBUTE(pure) getNoMusic()
{
    return noMusic();
}

float SSVU_ATTRIBUTE(pure) getSoundVolume()
{
    return soundVolume();
}

float SSVU_ATTRIBUTE(pure) getMusicVolume()
{
    return musicVolume();
}

bool SSVU_ATTRIBUTE(pure) getLimitFPS()
{
    return limitFPS();
}

bool SSVU_ATTRIBUTE(pure) getVsync()
{
    return vsync();
}

bool SSVU_ATTRIBUTE(pure) getAutoZoomFactor()
{
    return getOfficial() ? true : autoZoomFactor();
}

bool SSVU_ATTRIBUTE(pure) getFullscreen()
{
    return fullscreen();
}

float SSVU_ATTRIBUTE(const) getVersion()
{
    return 2.f;
}

const char* SSVU_ATTRIBUTE(const) getVersionString()
{
    return "2.0";
}

bool SSVU_ATTRIBUTE(pure) getWindowedAutoResolution()
{
    return windowedAutoResolution();
}

bool SSVU_ATTRIBUTE(pure) getFullscreenAutoResolution()
{
    return fullscreenAutoResolution();
}

unsigned int SSVU_ATTRIBUTE(pure) getFullscreenWidth()
{
    return fullscreenWidth();
}

unsigned int SSVU_ATTRIBUTE(pure) getFullscreenHeight()
{
    return fullscreenHeight();
}

unsigned int SSVU_ATTRIBUTE(pure) getWindowedWidth()
{
    return windowedWidth();
}

unsigned int SSVU_ATTRIBUTE(pure) getWindowedHeight()
{
    return windowedHeight();
}

unsigned int SSVU_ATTRIBUTE(pure) getWidth()
{
    return getFullscreen() ? getFullscreenWidth() : getWindowedWidth();
}

unsigned int SSVU_ATTRIBUTE(pure) getHeight()
{
    return getFullscreen() ? getFullscreenHeight() : getWindowedHeight();
}

bool SSVU_ATTRIBUTE(pure) getShowMessages()
{
    return showMessages();
}

bool SSVU_ATTRIBUTE(pure) getDebug()
{
    return getOfficial() ? false : debug();
}

bool SSVU_ATTRIBUTE(pure) getPulse()
{
    return getOfficial() ? true : pulseEnabled();
}

bool SSVU_ATTRIBUTE(pure) getBeatPulse()
{
    return getOfficial() ? true : beatPulse();
}

bool SSVU_ATTRIBUTE(pure) getInvincible()
{
    return getOfficial() ? false : invincible();
}

bool SSVU_ATTRIBUTE(pure) get3D()
{
    return _3DEnabled();
}

float SSVU_ATTRIBUTE(pure) get3DMultiplier()
{
    return _3DMultiplier();
}

unsigned int SSVU_ATTRIBUTE(pure) get3DMaxDepth()
{
    return _3DMaxDepth();
}

bool SSVU_ATTRIBUTE(pure) getAutoRestart()
{
    return autoRestart();
}

bool SSVU_ATTRIBUTE(pure) getFlash()
{
    return flashEnabled();
}

bool SSVU_ATTRIBUTE(pure) getShowTrackedVariables()
{
    return showTrackedVariables();
}

bool SSVU_ATTRIBUTE(pure) getMusicSpeedDMSync()
{
    return musicSpeedDMSync();
}

unsigned int SSVU_ATTRIBUTE(pure) getMaxFPS()
{
    return maxFPS();
}

unsigned int SSVU_ATTRIBUTE(pure) getAntialiasingLevel()
{
    return antialiasingLevel();
}

bool SSVU_ATTRIBUTE(pure) getShowFPS()
{
    return showFPS();
}

bool SSVU_ATTRIBUTE(pure) getTimerStatic()
{
    return timerStatic();
}

bool SSVU_ATTRIBUTE(pure) getServerLocal()
{
    return serverLocal();
}

bool SSVU_ATTRIBUTE(pure) getServerVerbose()
{
    return serverVerbose();
}

bool SSVU_ATTRIBUTE(pure) getMouseVisible()
{
    return mouseVisible();
}

float SSVU_ATTRIBUTE(pure) getMusicSpeedMult()
{
    return musicSpeedMult();
}

bool SSVU_ATTRIBUTE(pure) getDrawTextOutlines()
{
    return drawTextOutlines();
}

bool SSVU_ATTRIBUTE(pure) getDarkenUnevenBackgroundChunk()
{
    return darkenUnevenBackgroundChunk();
}

bool SSVU_ATTRIBUTE(pure) getRotateToStart()
{
    return rotateToStart();
}

float SSVU_ATTRIBUTE(pure) getJoystickDeadzone()
{
    return joystickDeadzone();
}

float SSVU_ATTRIBUTE(pure) getTextPadding()
{
    return textPadding();
}

float SSVU_ATTRIBUTE(pure) getTextScaling()
{
    return textScaling();
}

Trigger getTriggerRotateCCW()
{
    return triggerRotateCCW();
}

Trigger getTriggerRotateCW()
{
    return triggerRotateCW();
}

Trigger getTriggerFocus()
{
    return triggerFocus();
}

Trigger getTriggerExit()
{
    return triggerExit();
}

Trigger getTriggerForceRestart()
{
    return triggerForceRestart();
}

Trigger getTriggerRestart()
{
    return triggerRestart();
}

Trigger getTriggerScreenshot()
{
    return triggerScreenshot();
}

Trigger getTriggerSwap()
{
    return triggerSwap();
}

Trigger getTriggerUp()
{
    return triggerUp();
}

Trigger getTriggerDown()
{
    return triggerDown();
}

} // namespace hg::Config

#undef X_LINKEDVALUES