From 55af7ae0f136863f0781630e22c66b75b1afe3bc Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 22 Jul 2024 00:08:01 -0500 Subject: Get random phrases working and remove off-by-1 error --- src/Makefile | 3 ++- src/screen.c | 54 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/Makefile b/src/Makefile index 94d2674..55268aa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,7 @@ CC = gcc CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb +SHELL := /usr/bin/env -S bash BINARY_FILES := main encryption.o search.o ll.o .PHONY: all clean @@ -15,7 +16,7 @@ main: main.c search.o encryption.o ll.o encryption.o: encryption.c encryption.h screen: screen.c screen.h - $(CC) $(CFLAGS) screen.c -o screen -lncurses -lmenu + set -e -o pipefail && $(CC) $(CFLAGS) $$(pkg-config --cflags libsodium) screen.c -o screen -lncurses -lmenu $$(pkg-config --libs libsodium) search.o: search.c search.h ll.o: ll.c ll.h \ No newline at end of file diff --git a/src/screen.c b/src/screen.c index b9e0b11..598557a 100644 --- a/src/screen.c +++ b/src/screen.c @@ -24,21 +24,20 @@ SLOTS HERE #include "screen.h" #include -#include #include - +#include #include #include +#include #include -#include 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 Randomware Operators quit before compromising a bank", + "99% of Ransomware Operators quit before compromising a bank", "Equation Group wuz here", "Lazarus wuz here", "LockBit wuz here", @@ -74,8 +73,6 @@ static const char *phrases[] = { "Hab you seen a alien pls?", "using a flipperzero makes me an APT, right?", "Subscribe to PewDiePie", - - NULL }; static const char *menu_choices[] = { @@ -99,17 +96,25 @@ static int init_rgb_color(int colornum, int red, int green, int blue) { } 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, "Could not set proper locale"); + error(1, errno, "[VX-GAMBLEGROUND] Could not set proper locale"); if(initscr() == NULL) // Initialize curses - error(1, errno, "Could not init standard screen"); + 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); @@ -125,11 +130,29 @@ int main() { 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); + + wgetch(phrase); + /* Ignore for(int c = getch();; c = getch()) mvaddch(c % row, c % col, c | A_BOLD); @@ -174,21 +197,6 @@ int main() { free_menu(menu); //*/ - // Making this a subwindow of stdscr might be a good idea (maybe) - int height = 1; - int width = col; - int starty = 0; /* Calculating for a center placement */ - int startx = 0; /* of the window */ - - WINDOW *phrase = NULL; - phrase = newwin(height, width, starty, startx); - wbkgd(phrase, COLOR_PAIR(1)); - mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); - waddstr(phrase, phrases[1]); - wrefresh(phrase); - - wgetch(phrase); - endwin(); // Clean up curses return 0; } \ No newline at end of file -- cgit v1.2.3