2023-07-20 18:59:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <network.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
2023-07-27 11:56:50 +00:00
|
|
|
#include <jansson.h>
|
2023-07-21 07:47:59 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2023-07-20 19:10:01 +00:00
|
|
|
#include "sandia/sandia.h"
|
2023-07-27 11:56:50 +00:00
|
|
|
|
|
|
|
#include "input_macros.h"
|
2023-07-20 19:10:01 +00:00
|
|
|
|
2023-07-21 06:12:42 +00:00
|
|
|
// Uncomment if this is a development build
|
|
|
|
//#include "debug.h"
|
|
|
|
|
2023-07-20 18:59:22 +00:00
|
|
|
static void *xfb = NULL;
|
|
|
|
static GXRModeObj *rmode = NULL;
|
|
|
|
|
|
|
|
static char version[] = { "0.0dev\0" };
|
|
|
|
|
|
|
|
void printheader() {
|
|
|
|
printf("\x1b[44m");
|
|
|
|
printf(" \n");
|
|
|
|
printf(" LibreShop v%s \n", version);
|
|
|
|
printf(" \n");
|
|
|
|
printf("\x1b[40m\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void logprint(int type, char *message) {
|
|
|
|
switch(type) {
|
|
|
|
case 1:
|
|
|
|
printf("\x1b[34m[\x1b[32mOK\x1b[34m]");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
printf("\x1b[34m[\x1b[31m--\x1b[34m]");
|
2023-07-21 06:33:58 +00:00
|
|
|
break;
|
2023-07-20 18:59:22 +00:00
|
|
|
case 3:
|
|
|
|
printf("\x1b[31m!!\x1b[34m]");
|
2023-07-21 06:33:58 +00:00
|
|
|
break;
|
2023-07-20 18:59:22 +00:00
|
|
|
default:
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf(" \x1b[37m%s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
char localip[16] = {0};
|
|
|
|
char gateway[16] = {0};
|
|
|
|
char netmask[16] = {0};
|
|
|
|
|
|
|
|
VIDEO_Init();
|
|
|
|
|
|
|
|
WPAD_Init();
|
|
|
|
|
|
|
|
rmode = VIDEO_GetPreferredMode(NULL);
|
|
|
|
|
|
|
|
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
|
|
|
|
|
|
|
|
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
|
|
|
|
|
|
|
|
VIDEO_Configure(rmode);
|
|
|
|
|
|
|
|
VIDEO_SetNextFramebuffer(xfb);
|
|
|
|
|
|
|
|
VIDEO_SetBlack(FALSE);
|
|
|
|
|
|
|
|
VIDEO_Flush();
|
|
|
|
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\x1b[1;0H");
|
|
|
|
|
|
|
|
printheader();
|
|
|
|
logprint(0, "Welcome to LibreShop!\n");
|
2023-07-21 06:31:35 +00:00
|
|
|
#ifdef DEBUG_H
|
|
|
|
logprint(2, "Warning! You are running a DEBUG build.\n");
|
|
|
|
#endif
|
2023-07-20 18:59:22 +00:00
|
|
|
logprint(0, "Initializing network.\n");
|
|
|
|
|
|
|
|
ret = if_config(localip, netmask, gateway, TRUE, 20);
|
|
|
|
|
|
|
|
if (ret>=0) {
|
|
|
|
logprint(1, "Initialized successfully!\n");
|
|
|
|
logprint(0, "Your Wii's IP address is ");
|
|
|
|
printf("%s.\n", localip);
|
2023-07-20 19:10:01 +00:00
|
|
|
|
|
|
|
sandia req = sandia_create("libreshop.donut.eu.org", 80);
|
|
|
|
sandia_response res = sandia_get_request(&req, "/");
|
2023-07-21 07:47:59 +00:00
|
|
|
bool lastWasNewline = false;
|
|
|
|
int resBodyLength = strlen(res.body);
|
|
|
|
for (int i = 0; i < resBodyLength; i++) {
|
|
|
|
if (res.body[i] == '\r') continue;
|
|
|
|
|
|
|
|
if (res.body[i] == '\n') {
|
|
|
|
if (lastWasNewline) {
|
|
|
|
int rBL = resBodyLength - i;
|
|
|
|
char* body = malloc(rBL);
|
|
|
|
for (int j = 0; j < rBL; j++) {
|
|
|
|
body[j] = res.body[j + i + 1];
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:39:29 +00:00
|
|
|
json_error_t error;
|
|
|
|
json_t *root = json_loads(body, 0, &error);
|
|
|
|
if (!root || !json_is_array(root)) {
|
|
|
|
printf("failed decoding\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("%s\n", body);
|
|
|
|
for (int j = 0; j < json_array_size(root); j++) {
|
|
|
|
json_t *data = json_array_get(root, j);
|
|
|
|
printf("%s\n", json_string_value(data));
|
|
|
|
}
|
|
|
|
}
|
2023-07-21 07:47:59 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else lastWasNewline = true;
|
|
|
|
}
|
|
|
|
else lastWasNewline = false;
|
|
|
|
}
|
|
|
|
printf("\n");
|
2023-07-21 05:52:09 +00:00
|
|
|
sandia_close(&req);
|
2023-07-20 19:10:01 +00:00
|
|
|
} else {
|
2023-07-20 18:59:22 +00:00
|
|
|
logprint(0, "Network configuration failed :(\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
WPAD_ScanPads();
|
|
|
|
|
|
|
|
u32 pressed = WPAD_ButtonsDown(0);
|
|
|
|
|
2023-07-27 11:56:50 +00:00
|
|
|
if ( pressed && INPUT_BUTTON_HOME ) {
|
|
|
|
logprint(0, "HOME pressed, quitting!\n");
|
2023-07-20 18:59:22 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|