summaryrefslogtreecommitdiff
path: root/src/screen.c
blob: 9cdac023b0a086b837efa21224bf8a86ebd39126 (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
/***
 * Screen - The actual point of this godforsaken project
 * 
 * This file's goal is to "render" a slot machine that the soon-to-be unlucky victim must play to get their
 * files back. To do this, I am using curses and probably the menu library to create the TUI. Once I figure
 * out how to actually do this, everything should work hopefully maybe
 * 
Example window layout

======================================================== (Window 1)         (One line long, top of screen)
VX-GAMBLEGROUND: <Random phrase from list of phrases>
======================================================== (End Window 1)     (Takes up space between top & bottom windows)
======================================================== (Window 2)

SLOTS HERE

======================================================== (End Window 2)
======================================================== (Window 3)         (One line long, bottom of screen)
> Spin              > Buy Spins             > Quit
======================================================== (End Window 3)
 */

#define _GNU_SOURCE

#include "screen.h"
#include <curses.h>
#include <locale.h>
#include <sodium.h>
#include <errno.h>
#include <error.h>
#include <menu.h>

#include <stdio.h>

static const char *phrases[] = {
    // By @syxhe on telegram 
    "WE CLOWN IN THIS MF, TAKE YO SENSITIVE ASS BACK TO @GENTOOMEMES",
    "R.I.P VxHeaven",
    "tmp(2) nuked by Smelly",
    "99% of Ransomware Operators quit before compromising a bank",
    "Equation Group wuz here",
    "Lazarus wuz here",
    "LockBit wuz here",
    "Sponsored by Equation Group",
    "Sponsored by Lazarus",
    "Sponsored by LockBit",
    "Free my boy Ross Ulbricht he did nothing wrong",
    "Stay off the dark web, kids",
    "FREE BITCOIN JUST 3 SPINS AWAY",
    "We all glow in the dark",
    "Shoutouts to Simpleflips",
    "Shoutouts to BugHunter",
    "Shoutouts to EyeDeeKay",
    ":beecat:",
    ":3",
    "You think Jack Rhysider will interview me now?",
    "Check out \"Darknet Diaries\"",

    // by @danielsprofile on telegram
    "Daniel Spears loves femboys",
    "LizardSquad > Razer",
    "Sponsored by Major League Gaming",
    "Sponsored by LemonParty.org",
    "Sponsored by FTX",
    "RIP Harambe",
    "Shoutout Elliot Alderson",
    "Ted Kaczynski was right",
    "The FBI watches me jerk off to MILFs lol",
    "robux generator free online 2024 100% working undetected",
    "Doge wuz here",
    "We like Fortnite we like Fortnite",
    "We live in a society",
    "Hab you seen a alien pls?",
    "using a flipperzero makes me an APT, right?",
    "Subscribe to PewDiePie",
};

static const char *menu_choices[] = {
    "Spin",
    "Buy spins",
    "Quit",
    NULL
};

static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) {
    // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range
    return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin;
}

static int init_rgb_color(int colornum, int red, int green, int blue) {
    int nred    = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
    int ngreen  = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
    int nblue   = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);

    return init_color(colornum, nred, ngreen, nblue);
}

int main() {
    if(sodium_init() < 0)
        error(1, errno, "[VX-GAMBLEGROUND] Could not initialize sodium");

    if(setlocale(LC_ALL, "") == NULL)  // Clear out the locale so it doesn't default to ncurses' ISO-8859-1 setting
        error(1, errno, "[VX-GAMBLEGROUND] Could not set proper locale");

    if(initscr() == NULL)   // Initialize curses
        error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen");

    if(has_colors() && can_change_color()) {      // Init colors if available & create color pairings
        start_color();

        // Init colors here
        // TODO: FIGURE OUT WHY COLORS ARE SO FUCKEY
            /* The colors were being weird because I was being retarded and redefining already existing colors
            // to numbers well outside curses' 0-1000 range. Making an enum that redefined the already existing 
            // curses colors made this go away. Also VSCode's terminal theming is fucking with it as well, so
            // use a normal terminal for accurate colors */
        
        init_rgb_color(CC_RED, 255, 0, 0);
        init_rgb_color(CC_ORANGE, 255, 128, 0);
        init_rgb_color(CC_YELLOW, 255, 255, 0);
        init_rgb_color(CC_GREEN, 0, 255, 0);
        init_rgb_color(CC_BLUE, 0, 0, 255);
        init_rgb_color(CC_PURPLE, 255, 0, 255);
        init_rgb_color(CC_WHITE, 255, 255, 255);

        init_pair(1, CC_WHITE, CURSES_BLUE);

    }

    cbreak();               // Disables character buffering
    noecho();               // Disable echoing characters
    keypad(stdscr, TRUE);   // Enable keypad on the standard screen
    curs_set(0);

    int row = -1, col = -1;
    getmaxyx(stdscr, row, col);


    int randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases));
    if(randomnum < 0)
        error(1, errno, "[VX-GAMBLEGROUND] Call to randombytes_uniform failed, can't get random phrase");

    // Making this a subwindow of stdscr might be a good idea (maybe)
    WINDOW *phrase = NULL;
    phrase = newwin(1, col, 0, 0);
    if(phrase == NULL)
        error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window");

    wbkgd(phrase, COLOR_PAIR(1));
    mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: ");
    waddstr(phrase, phrases[randomnum]);
    wrefresh(phrase);

    //* Dummy test for fun. Shows how windows can't be overlapping or things get weird
    WINDOW *test = newwin(row - 1, col, 1, 0);
    for(int c = wgetch(test);; c = wgetch(test)) {
        mvwaddch(test, c % row, c % col, c | (A_BOLD * (randombytes_random() % 2 > 0)));
    }
    //*/

    /* Menu example
    ITEM **items;
    MENU *menu;

    items = calloc(STATIC_ARRSIZE(menu_choices) + 1, sizeof(ITEM*));
    if(items == NULL)
        error(-1, errno, "Could not allocate space for menu items");

    for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++)
        items[i] = new_item(menu_choices[i], menu_choices[i]);
    items[STATIC_ARRSIZE(menu_choices)] = NULL;

    menu = new_menu(items);
    mvprintw(LINES - 2, 0, "F1 to Exit");
    post_menu(menu);
    refresh();

    int c;
    while((c = getch()) != KEY_F(1)) {
        switch(c) {
            case KEY_DOWN:
                menu_driver(menu, REQ_DOWN_ITEM);
                break;

            case KEY_UP:
                menu_driver(menu, REQ_UP_ITEM);
                break;

            case KEY_ENTER:
                break;
        }
    }


    for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++)
        free_item(items[i]);
    free_menu(menu);
    //*/

    endwin(); // Clean up curses
    return 0;
}