Start gg started
This commit is contained in:
parent
1c017747dd
commit
414a31e711
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
|||
CC=cc
|
||||
CFLAGS=--std=c99 -g `pkg-config --cflags efl ecore elementary libusb-1.0` `sdl2-config --cflags`
|
||||
LDFLAGS=`pkg-config --libs efl ecore elementary libusb-1.0` `sdl2-config --libs` -lcjson
|
||||
OBJS=main.o replay.o home.o input.o
|
||||
OBJS=main.o replay.o home.o input.o http.o gg.o
|
||||
|
||||
minilauncher4slippi: $(OBJS)
|
||||
$(CC) -o minilauncher4slippi $(OBJS) $(LDFLAGS)
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
#include <cjson/cJSON.h>
|
||||
#include "gg.h"
|
||||
#include "http.h"
|
||||
|
||||
Evas_Object* tab_gg = NULL;
|
||||
static Evas_Object* tab_gg_sidebar;
|
||||
static Evas_Object* tab_gg_content;
|
||||
extern char* start_gg_api;
|
||||
|
||||
static void
|
||||
_gg_sidebar_cb(void *_data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Evas_Object** data = _data;
|
||||
//update_tab(*data);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_gg_scrape_result(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
|
||||
{
|
||||
Ecore_Con_Event_Url_Complete* ev = event_info;
|
||||
struct memory_chunk* dd = ecore_con_url_data_get(ev->url_con);
|
||||
|
||||
#define magiccode "script id=\"__NEXT_DATA__\" type=\"application/json\">"
|
||||
char* start_json = strstr(dd->data, magiccode);
|
||||
if (!start_json)
|
||||
return EINA_FALSE; // Some error
|
||||
start_json += sizeof(magiccode) - 1;
|
||||
|
||||
char* end_json = strstr(start_json, "</script><script>");
|
||||
if (!end_json)
|
||||
return EINA_FALSE;
|
||||
*end_json = '\0';
|
||||
#undef magiccode
|
||||
|
||||
puts(start_json);
|
||||
|
||||
// Data required is scraped now!
|
||||
cJSON* json = cJSON_Parse(start_json);
|
||||
if (!json)
|
||||
{
|
||||
fprintf(stderr, "Something happened.\n");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
cJSON* props = cJSON_GetObjectItemCaseSensitive(json, "props");
|
||||
cJSON* pageProps = cJSON_GetObjectItemCaseSensitive(props, "pageProps");
|
||||
cJSON* currentUserFetchSpec = cJSON_GetObjectItemCaseSensitive(
|
||||
pageProps, "currentUserFetchSpec");
|
||||
cJSON* entities = cJSON_GetObjectItemCaseSensitive(currentUserFetchSpec, "entities");
|
||||
cJSON* tournament = cJSON_GetObjectItemCaseSensitive(entities, "tournament");
|
||||
int i = 0;
|
||||
for (cJSON* c = tournament->child; c->next != NULL; (++i, c = c->next))
|
||||
{
|
||||
printf("name: %s\n", cJSON_GetObjectItemCaseSensitive(c, "name")->valuestring);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_gg_scrape_homepage(char* token)
|
||||
{
|
||||
Ecore_Con_Url* ec_url = ecore_con_url_custom_new("https://www.start.gg/", "GET");
|
||||
ecore_con_url_data_set(ec_url, memory_chunk_alloc());
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, memory_chunk_data, NULL);
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _gg_scrape_result, NULL);
|
||||
ecore_con_url_additional_header_add(ec_url, "User-Agent", ":^)'); DROP TABLE users; --");
|
||||
ecore_con_url_additional_header_add(ec_url, "Accept", "*/*");
|
||||
|
||||
// "API" Token
|
||||
Eina_Strbuf* sesh = eina_strbuf_new();
|
||||
eina_strbuf_append_printf(sesh, "gg_session=%s;", token);
|
||||
ecore_con_url_additional_header_add(ec_url, "Cookie", eina_strbuf_string_get(sesh));
|
||||
free(eina_strbuf_release(sesh));
|
||||
|
||||
ecore_con_url_get(ec_url);
|
||||
}
|
||||
|
||||
Evas_Object*
|
||||
gg_create_view(Evas_Object* parent)
|
||||
{
|
||||
Evas_Object* tb_it;
|
||||
tab_gg = elm_box_add(parent);
|
||||
elm_box_horizontal_set(tab_gg, EINA_TRUE);
|
||||
evas_object_size_hint_weight_set(tab_gg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tab_gg, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(tab_gg);
|
||||
|
||||
tab_gg_sidebar = elm_toolbar_add(tab_gg);
|
||||
elm_toolbar_horizontal_set(tab_gg_sidebar, EINA_FALSE);
|
||||
//elm_object_style_set(tab_gg_sidebar, "item_vertical");
|
||||
elm_toolbar_homogeneous_set(tab_gg_sidebar, EINA_TRUE);
|
||||
elm_toolbar_shrink_mode_set(tab_gg_sidebar, ELM_TOOLBAR_SHRINK_MENU);
|
||||
evas_object_size_hint_weight_set(tab_gg_sidebar, 0.0, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tab_gg_sidebar, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(tab_gg, tab_gg_sidebar);
|
||||
|
||||
tb_it = elm_toolbar_item_append(tab_gg_sidebar, "home", NULL, _gg_sidebar_cb, NULL);
|
||||
elm_toolbar_item_priority_set(tb_it, 100);
|
||||
tb_it = elm_toolbar_item_append(tab_gg_sidebar, "mail-unread", NULL, _gg_sidebar_cb, NULL);
|
||||
elm_toolbar_item_priority_set(tb_it, 100);
|
||||
//-----
|
||||
elm_toolbar_item_separator_set(
|
||||
elm_toolbar_item_append(tab_gg_sidebar, NULL, NULL, NULL, NULL), EINA_TRUE);
|
||||
_gg_scrape_homepage(start_gg_api);
|
||||
//-----
|
||||
#if 0
|
||||
elm_toolbar_item_separator_set(
|
||||
elm_toolbar_item_append(tab_gg_sidebar, NULL, NULL, NULL, NULL), EINA_TRUE);
|
||||
tb_it = elm_toolbar_item_append(tab_gg_sidebar, "view-list-compact", "", _gg_sidebar_cb, NULL);
|
||||
elm_toolbar_item_priority_set(tb_it, 100);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Evas_Object* tab_gg_scr = elm_scroller_add(tab_gg);
|
||||
evas_object_size_hint_weight_set(tab_gg_scr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tab_gg_scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(tab_gg, tab_gg_scr);
|
||||
evas_object_show(tab_gg_scr);
|
||||
|
||||
tab_gg_content = elm_box_add(tab_gg_scr);
|
||||
evas_object_size_hint_weight_set(tab_gg_content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tab_gg_content, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(tab_gg_content);
|
||||
|
||||
elm_object_content_set(tab_gg_scr, tab_gg_content);
|
||||
evas_object_show(tab_gg_content);
|
||||
evas_object_show(tab_gg_scr);
|
||||
evas_object_show(tab_gg_sidebar);
|
||||
evas_object_show(tab_gg);
|
||||
|
||||
return tab_gg;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/* A question worth asking: Why not make the GG stuff an actual library?
|
||||
* The reason: start.gg is DOGSHIT, there are several API's, all of which are functionally
|
||||
* different and broken in their own ways. You have no real clue when stuff is going
|
||||
* to change, and some parts are _COMPLETELY_ undocumented. Some of the API's return
|
||||
* up to 88kb (!!!) of data... it's so horrific and bade i do not want to... go into it.
|
||||
*
|
||||
* Alas, I have no motivation to make this its own API. There are also Python wrappers and
|
||||
* such, which is good especially if you need statistics from matches.
|
||||
*/
|
||||
|
||||
#ifndef GG_API_H
|
||||
#define GG_API_H
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
#include <Ecore.h>
|
||||
#include <Elementary.h>
|
||||
|
||||
extern Evas_Object* tab_gg;
|
||||
|
||||
Evas_Object*
|
||||
gg_create_view(Evas_Object* parent);
|
||||
|
||||
#endif /* GG_API_H */
|
37
home.c
37
home.c
|
@ -2,30 +2,12 @@
|
|||
#include <cjson/cJSON.h>
|
||||
#include <stdint.h>
|
||||
#include "replay.h"
|
||||
#include "http.h"
|
||||
|
||||
Evas_Object* tab_home = NULL;
|
||||
static Evas_Object* tab_home_scr = NULL;
|
||||
static Evas_Object* tab_home_content = NULL;
|
||||
char const* home_url = "https://api.github.com/repos/project-slippi/Ishiiruka/releases";
|
||||
|
||||
struct memory_chunk {
|
||||
char* data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static Eina_Bool
|
||||
releases_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
|
||||
{
|
||||
Ecore_Con_Event_Url_Data* ev = event_info;
|
||||
struct memory_chunk* dd = ecore_con_url_data_get(ev->url_con);
|
||||
|
||||
dd->data = realloc(dd->data, dd->size + ev->size + 1);
|
||||
|
||||
memcpy(dd->data + dd->size, ev->data, ev->size);
|
||||
dd->size += ev->size;
|
||||
dd->data[dd->size] = 0;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
releases_result(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
|
||||
|
@ -109,13 +91,13 @@ releases_result(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
|
|||
void
|
||||
_tab_home_make_da_damn_request(Evas_Object* parent)
|
||||
{
|
||||
ecore_con_init();
|
||||
ecore_con_url_init();
|
||||
//ecore_con_init();
|
||||
//ecore_con_url_init();
|
||||
Ecore_Con_Url* ec_url = ecore_con_url_custom_new(home_url, "GET");
|
||||
ecore_con_url_data_set(ec_url, calloc(1, sizeof(struct memory_chunk)));
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, releases_data, NULL);
|
||||
ecore_con_url_data_set(ec_url, memory_chunk_alloc());
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, memory_chunk_data, NULL);
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, releases_result, parent);
|
||||
ecore_con_url_additional_header_add(ec_url, "User-Agent", "blablabla");
|
||||
ecore_con_url_additional_header_add(ec_url, "User-Agent", ":^)'); DROP TABLE issues; --");
|
||||
ecore_con_url_additional_header_add(ec_url, "Accept", "application/vnd.github.html");
|
||||
ecore_con_url_get(ec_url);
|
||||
}
|
||||
|
@ -126,18 +108,15 @@ tab_home_setup(Evas_Object* parent)
|
|||
tab_home = elm_box_add(parent); // Scroller
|
||||
evas_object_size_hint_weight_set(tab_home, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tab_home, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(tab_home);
|
||||
|
||||
tab_home_scr = elm_scroller_add(tab_home);
|
||||
Evas_Object* tab_home_scr = elm_scroller_add(tab_home);
|
||||
evas_object_size_hint_weight_set(tab_home_scr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tab_home_scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(tab_home, tab_home_scr);
|
||||
evas_object_show(tab_home_scr);
|
||||
|
||||
tab_home_content = elm_box_add(tab_home_scr);
|
||||
evas_object_size_hint_weight_set(tab_home_content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tab_home_content, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(tab_home_content);
|
||||
|
||||
elm_object_content_set(tab_home_scr, tab_home_content);
|
||||
|
||||
|
@ -145,7 +124,7 @@ tab_home_setup(Evas_Object* parent)
|
|||
evas_object_show(tab_home_scr);
|
||||
evas_object_show(tab_home);
|
||||
|
||||
_tab_home_make_da_damn_request(tab_home_content);
|
||||
// _tab_home_make_da_damn_request(tab_home_content);
|
||||
|
||||
// Add progress bar for noa
|
||||
Evas_Object* speen = elm_progressbar_add(tab_home_content);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#define EFL_BETA_API_SUPPORT
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Con.h>
|
||||
#include <stdio.h>
|
||||
#include "http.h"
|
||||
|
||||
struct memory_chunk*
|
||||
memory_chunk_alloc(void)
|
||||
{
|
||||
struct memory_chunk* data = calloc(1, sizeof(struct memory_chunk));
|
||||
if (!data)
|
||||
{
|
||||
perror("memory_chunk_alloc");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
memory_chunk_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
|
||||
{
|
||||
Ecore_Con_Event_Url_Data* ev = event_info;
|
||||
struct memory_chunk* dd = ecore_con_url_data_get(ev->url_con);
|
||||
|
||||
dd->data = realloc(dd->data, dd->size + ev->size + 1);
|
||||
|
||||
memcpy(dd->data + dd->size, ev->data, ev->size);
|
||||
dd->size += ev->size;
|
||||
dd->data[dd->size] = 0;
|
||||
return EINA_TRUE;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef HTTP_H
|
||||
#define HTTP_H
|
||||
#include <Ecore.h>
|
||||
|
||||
struct memory_chunk {
|
||||
char* data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct memory_chunk*
|
||||
memory_chunk_alloc(void);
|
||||
|
||||
Eina_Bool
|
||||
memory_chunk_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info);
|
||||
|
||||
#endif /* HTTP_H */
|
18
main.c
18
main.c
|
@ -1,7 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
#include <Ecore.h>
|
||||
#include <Efl_Ui.h>
|
||||
#include <Elementary.h>
|
||||
#include <libusb.h>
|
||||
#include "replay.h"
|
||||
|
@ -14,6 +13,7 @@ int opt_mallocd = -1;
|
|||
char* game_path = "SSBM.iso";
|
||||
char* dolphin_emu_file = "slippi-netplay-dolphin";
|
||||
char* dolphin_replay_file = "slippi-playback-dolphin";
|
||||
char* start_gg_api = ":^)";
|
||||
#ifndef DATA_DIR
|
||||
#define DATA_DIR "data/"
|
||||
#endif
|
||||
|
@ -24,6 +24,7 @@ Evas_Object* win;
|
|||
Evas_Object* _tab_curr;
|
||||
extern Evas_Object* tab_home;
|
||||
extern Evas_Object* tab_replays;
|
||||
extern Evas_Object* tab_gg;
|
||||
Evas_Object* _tabs[] = { NULL, NULL };
|
||||
Evas_Object* _scrollers[] = { NULL, NULL };
|
||||
int _tabs_len = 2;
|
||||
|
@ -72,9 +73,10 @@ parse_config(char* file)
|
|||
*rdpnt = '\0';
|
||||
switch (i)
|
||||
{
|
||||
case 0: game_path = strdup(buf); break;
|
||||
case 1: dolphin_emu_file = strdup(buf); break;
|
||||
case 2: dolphin_replay_file = strdup(buf); break;
|
||||
case 0: game_path = strdup(buf); break;
|
||||
case 1: dolphin_emu_file = strdup(buf); break;
|
||||
case 2: dolphin_replay_file = strdup(buf); break;
|
||||
case 3: start_gg_api = strdup(buf); break;
|
||||
}
|
||||
++opt_mallocd;
|
||||
}
|
||||
|
@ -155,6 +157,8 @@ tabs_init()
|
|||
// BEGIN tab_replays
|
||||
_tabs[1] = tab_replays_setup(mainer);
|
||||
|
||||
_tabs[2] = gg_create_view(mainer);
|
||||
|
||||
// Show home tab at start
|
||||
_tab_curr = tab_home;
|
||||
evas_object_show(_tab_curr);
|
||||
|
@ -229,9 +233,13 @@ elm_main(int argc, char **argv)
|
|||
tb_it = elm_toolbar_item_append(tb, "media-seek-backward", "Replays", _tab_switch_cb, &tab_replays);
|
||||
elm_toolbar_item_priority_set(tb_it, -100);
|
||||
|
||||
tb_it = elm_toolbar_item_append(tb, "network-cellular-gprs", "Start.gg", _tab_switch_cb, &tab_gg);
|
||||
elm_toolbar_item_priority_set(tb_it, 149);
|
||||
|
||||
tb_it = elm_toolbar_item_append(tb, "preferences-system", "Settings", _tab_switch_cb, &tab_config);
|
||||
elm_toolbar_item_priority_set(tb_it, 150);
|
||||
|
||||
|
||||
tb_it = elm_toolbar_item_append(tb, "network-wireless", NULL, NULL, NULL);
|
||||
elm_toolbar_item_menu_set(tb_it, EINA_TRUE);
|
||||
elm_toolbar_item_priority_set(tb_it, -9999);
|
||||
|
@ -318,7 +326,7 @@ elm_main(int argc, char **argv)
|
|||
if (opt_mallocd >= 0) free(game_path);
|
||||
if (opt_mallocd >= 1) free(dolphin_emu_file);
|
||||
if (opt_mallocd >= 2) free(dolphin_replay_file);
|
||||
|
||||
if (opt_mallocd >= 3) free(start_gg_api);
|
||||
return 0;
|
||||
}
|
||||
ELM_MAIN()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
SSBM.iso
|
||||
slippi-netplay-dolphin
|
||||
slippi-playback-dolphin
|
||||
37f23dbe87a3ed1abd77df833fbf6088
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 85 KiB |
Loading…
Reference in New Issue