From 0ed6c602b14554a02f7782bd5e5635b1e9d9c195 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Fri, 3 Jul 2026 22:02:56 -0500 Subject: init --- src/config.def.c | 15 +++++++ src/main.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/title.sh | 22 ++++++++++ src/type.c | 64 +++++++++++++++++++++++++++++ 4 files changed, 224 insertions(+) create mode 100644 src/config.def.c create mode 100644 src/main.c create mode 100755 src/title.sh create mode 100644 src/type.c (limited to 'src') diff --git a/src/config.def.c b/src/config.def.c new file mode 100644 index 0000000..90004de --- /dev/null +++ b/src/config.def.c @@ -0,0 +1,15 @@ +#ifndef config +#define config + +#define arr_size 3 //change this to how many messages you want to cycle through + +char *title="title"; //change the title here +char *arr[arr_size]; + +void init_arr(){ + arr[0]="message 1"; //copy and paste this then change the number to the message your editing + arr[1]="message 2"; + arr[2]="message 3"; +} + +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..57e3ced --- /dev/null +++ b/src/main.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.c" +#include "tinyosc.c" +#include "tinyosc.h" + +/* + chat-loop / main.c. sends text to vrchat using osc. + Copyright (C) 2026 iceyrazor + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +static volatile bool keepRunning = true; + +// handle Ctrl+C +static void sigintHandler(int x) +{ + keepRunning = false; +} + +// execute command and put output into ret_buf buffer +void execlb(char* cmd, char* ret_buf) +{ + int link[2]; + pid_t pid; + char buf[2048]; + + if (pipe(link) == -1) + exit(-5); + + if ((pid = fork()) == -1) + exit(-5); + + if (pid == 0) { + + dup2(link[1], STDOUT_FILENO); + close(link[0]); + close(link[1]); + execl("/bin/sh", "sh", "-c", cmd, (char*)0); + exit(0); + + } else { + + close(link[1]); + int nbytes = read(link[0], buf, sizeof(buf)); + if (nbytes > 2047) + nbytes = 2047; + snprintf(ret_buf, nbytes + 1, "%s", buf); + wait(NULL); + close(link[0]); + } +} + +int main() +{ + char wbuffer[2048]; // declare a 2Kb buffer to read packet data into + int port = 9000; + struct sockaddr_in servaddr; + + int socketfd = socket(AF_INET, SOCK_DGRAM, 0); + if (socketfd < 0) { + perror("ERROR:"); + return -1; + } + + servaddr.sin_family = AF_INET; // IPv4 + servaddr.sin_port = htons(port); // Server port + servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Server IP + // register the SIGINT handler (Ctrl+C) + signal(SIGINT, &sigintHandler); + + char* dist = (char*)malloc(sizeof(char) * 2048); + execlb("uname -r", dist); + dist[strlen(dist) - 1] = '\0'; + + init_arr(); + + char* comb_string = (char*)malloc(sizeof(char) * 2048); + char* song_title = (char*)malloc(sizeof(char) * 2048); + + int i = 0; + + while (keepRunning) { + execlb("src/title.sh", song_title); + sprintf(comb_string, "%s\nLinux %s\n%s\n%s", title, dist, arr[i], song_title); + + int len = 0; + len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", comb_string); + sendto(socketfd, wbuffer, len, MSG_CONFIRM, (const struct sockaddr*)&servaddr, sizeof(servaddr)); + + sleep(3); + + i = i + 1; + if (i >= arr_size) + i = 0; + } + + free(comb_string); + free(dist); + free(song_title); + + return 0; +} diff --git a/src/title.sh b/src/title.sh new file mode 100755 index 0000000..e83d91c --- /dev/null +++ b/src/title.sh @@ -0,0 +1,22 @@ +#!/bin/bash +status="$(playerctl status)" + +output="" + +echo "$status" | grep Playing > /dev/null && output="♫▶ " +echo "$status" | grep Paused > /dev/null && output="♫⏸️ " +echo "$status" | grep Stopped > /dev/null && output="♫⏹️ " + +# set to 1 to enable song title and artist name +en=0 +if [ $en = 1 ]; then + title="$(playerctl metadata title)" + artist="$(playerctl metadata artist)" + if [ "$artist" ]; then + output=$(printf -- "%s%s | %s" "$output" "$title" "$artist") + else + output=$(printf -- "%s%s" "$output" "$title") + fi +fi + +printf -- "%s" "$output" diff --git a/src/type.c b/src/type.c new file mode 100644 index 0000000..19548e9 --- /dev/null +++ b/src/type.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tinyosc.h" +#include "tinyosc.c" + +/* + type.c. sends text to vrchat using osc from user input. + Copyright (C) 2026 iceyrazor + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +int main(int argc, char **argv){ + char wbuffer[2048]; // declare a 2Kb buffer to read packet data into + int port=9000; + struct sockaddr_in servaddr; + + int socketfd = socket(AF_INET, SOCK_DGRAM, 0); + if (socketfd < 0) { + perror("ERROR:"); + return -1; + } + + servaddr.sin_family = AF_INET; // IPv4 + servaddr.sin_port = htons(port); // Server port + servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Server IP + + size_t size=0; + for (int i=1; i < argc; i++){ + size+=strlen(argv[i])+1; + } + char *send_str=(char*)malloc(sizeof(char)*size+1); + send_str[0]='\0'; + for (int i=1; i < argc; i++){ + strcat(send_str,argv[i]); + strcat(send_str," "); + } + + int len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", send_str); + sendto(socketfd, wbuffer, len, MSG_CONFIRM, (const struct sockaddr *)&servaddr, sizeof(servaddr)); + + free(send_str); + + return 0; +} -- cgit v1.3