From b387c10359991934e614936d9ea0cb0895812beb Mon Sep 17 00:00:00 2001 From: Alvarito050506 Date: Tue, 22 Jun 2021 10:22:56 +0000 Subject: [PATCH] Added option to hide launcher + fixes. + Fixed a memory leak somewhere. + Fixed multiplayer on non-ARM systems. --- Makefile | 10 ++++---- res/doc/gmcpil/CHANGELOG.txt | 4 ++++ src/callbacks.c | 20 ++++++++++++---- src/config.c | 46 ++++++++++++++---------------------- src/helpers.c | 11 ++++----- src/include/config.h | 28 +++++++++++++++++----- src/include/mcpil.h | 7 +----- src/include/servers.h | 1 - src/include/splashes.h | 1 - src/mcpil.c | 2 -- src/mods/multiplayer.c | 1 - src/tabs.c | 35 +++++++++++++-------------- 12 files changed, 87 insertions(+), 79 deletions(-) diff --git a/Makefile b/Makefile index e1d3272..309cdca 100644 --- a/Makefile +++ b/Makefile @@ -34,12 +34,14 @@ STRIP:=strip ARCH:=$(shell $(CC) -print-multiarch | grep -Eo "arm|aarch|86|x86_64") endif +VERSION:=0.11.0 + OBJS:=$(patsubst %,build/%.o,mcpil config helpers callbacks tabs) MODS:=$(patsubst %,build/lib%.so,multiplayer) LDFLAGS+=-Wl,--no-undefined -CFLAGS:=-I./src/include -Wall +CFLAGS:=-DGMCPIL_VERSION=\"v$(VERSION)\" -I./src/include -Wall GTK_CFLAGS:=`pkg-config --cflags gtk+-3.0 json-glib-1.0` GTK_LDFLAGS:=`pkg-config --libs gtk+-3.0 json-glib-1.0` MOD_CONFIG:=--shared -ldl @@ -54,8 +56,6 @@ endif # for internal functions, so let's "ignore" it. CFLAGS+=-Wno-error=deprecated-declarations -VERSION:=0.10.2 - .PHONY: ./build/gmcpil ./build/gmcpil: mkdir $(MODS) $(OBJS) @@ -80,9 +80,9 @@ pack: ./build/gmcpil mkdir -p ./deb/DEBIAN/ mkdir -p ./deb/usr/bin/ mkdir -p ./deb/usr/share/ - mkdir -p ./deb/usr/lib/gmcpil/ + mkdir -p ./deb/opt/minecraft-pi-reborn-client/mods/ cp ./build/gmcpil ./deb/usr/bin/ - cp ./build/lib*.so ./deb/usr/lib/gmcpil/ + cp ./build/lib*.so ./deb/opt/minecraft-pi-reborn-client/mods/ cp -r ./res/. ./deb/usr/share/ chmod a+x ./deb/usr/bin/gmcpil @echo "Package: gmcpil" > ./deb/DEBIAN/control diff --git a/res/doc/gmcpil/CHANGELOG.txt b/res/doc/gmcpil/CHANGELOG.txt index c1a08aa..59f134c 100644 --- a/res/doc/gmcpil/CHANGELOG.txt +++ b/res/doc/gmcpil/CHANGELOG.txt @@ -1,3 +1,7 @@ +v0.11.0: + + Added option to hide the launcher. + + Fixed multiplayer on non-ARM systems. + v0.10.2: + Fixed bug that mixed HUD and username settings. diff --git a/src/callbacks.c b/src/callbacks.c index ea00bde..7bc30a9 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #define _GNU_SOURCE /* Required for asprintf */ @@ -111,24 +110,28 @@ void multiplayer_cb(__attribute__((unused)) GtkWidget* button, __attribute__((un void watch_cb(GPid pid, __attribute__((unused)) int status, __attribute__((unused)) void* udata) { + gtk_widget_show_all(window); g_spawn_close_pid(pid); return; } void launch_cb(__attribute__((unused)) GtkWidget* button, __attribute__((unused)) void* udata) { - char* argv[] = {"/bin/sh", "-c", "minecraft-pi-reborn-client", NULL}; + char* argv[] = {"minecraft-pi-reborn-client", NULL}; GPid pid; GError* err = NULL; - g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &err); + g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &err); if (err != NULL) { g_error("Spawning child failed: %s", err->message); return; } - + if (mcpil_config_get_hide(config)[0] == 'T') + { + gtk_widget_hide(window); + } g_child_watch_add(pid, watch_cb, NULL); return; } @@ -152,6 +155,7 @@ void settings_cb(__attribute__((unused)) GtkWidget* button, __attribute__((unuse const char* username; const char* distance; const char* hud; + gboolean hide; GtkEntryBuffer* username_buff; GtkEntryBuffer* hud_buff; @@ -161,6 +165,7 @@ void settings_cb(__attribute__((unused)) GtkWidget* button, __attribute__((unuse username = gtk_entry_buffer_get_text(username_buff); distance = gtk_combo_box_text_get_active_text(settings_box.distance_combo); hud = gtk_entry_buffer_get_text(hud_buff); + hide = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(settings_box.hide_check)); setenv("MCPI_USERNAME", username, 1); setenv("MCPI_RENDER_DISTANCE", distance, 1); @@ -169,6 +174,13 @@ void settings_cb(__attribute__((unused)) GtkWidget* button, __attribute__((unuse mcpil_config_set_username(config, username); mcpil_config_set_distance(config, distance); mcpil_config_set_hud(config, hud); + if (hide) + { + mcpil_config_set_hide(config, "TRUE"); + } else + { + mcpil_config_set_hide(config, "FALSE"); + } mcpil_config_save(config); return; } diff --git a/src/config.c b/src/config.c index eea71df..d7e3fce 100644 --- a/src/config.c +++ b/src/config.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #include @@ -37,6 +36,7 @@ struct __attribute__((packed)) MCPILConfigPrivate gchar* distance; gchar* last_profile; gchar* hud; + gchar* hide; gchar* filename; }; @@ -50,6 +50,7 @@ enum PROP_DISTANCE, PROP_LAST_PROFILE, PROP_HUD, + PROP_HIDE, PROP_LAST }; @@ -69,26 +70,14 @@ static void mcpil_config_class_init(MCPILConfigClass* klass) gobject_class->get_property = mcpil_config_get_property; gobject_class->set_property = mcpil_config_set_property; - pspec = g_param_spec_string("ip", "IP", "Server IP", NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_IP, pspec); - - pspec = g_param_spec_string("port", "Port", "Server Port", NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_PORT, pspec); - - pspec = g_param_spec_string("username", "Username", "Player name", NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_USERNAME, pspec); - - pspec = g_param_spec_string("features", "Features", "MCPI-Reborn features", NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_FEATURES, pspec); - - pspec = g_param_spec_string("distance", "Distance", "Render distance", NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_DISTANCE, pspec); - - pspec = g_param_spec_string("last_profile", "Last profile", "Last selected profile", NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_LAST_PROFILE, pspec); - - pspec = g_param_spec_string("hud", "Gallium HUD", "Gallium HUD options", NULL, G_PARAM_READWRITE); - g_object_class_install_property(gobject_class, PROP_HUD, pspec); + MCPIL_GLIB_PROPERTY("ip", "IP", "Server IP", PROP_IP); + MCPIL_GLIB_PROPERTY("port", "Port", "Server Port", PROP_PORT); + MCPIL_GLIB_PROPERTY("username", "Username", "Player name", PROP_USERNAME); + MCPIL_GLIB_PROPERTY("features", "Features", "MCPI-Reborn features", PROP_FEATURES); + MCPIL_GLIB_PROPERTY("distance", "Distance", "Render distance", PROP_DISTANCE); + MCPIL_GLIB_PROPERTY("last_profile", "Last profile", "Last selected profile", PROP_LAST_PROFILE); + MCPIL_GLIB_PROPERTY("hud", "Gallium HUD", "Gallium HUD options", PROP_HUD); + MCPIL_GLIB_PROPERTY("hide", "Hide launcher", "Hide launcher on launch", PROP_HIDE); return; } @@ -126,13 +115,14 @@ static void mcpil_config_finalize(GObject* obj) return; } -GETTER_SETTER(gchar*, ip); -GETTER_SETTER(gchar*, port); -GETTER_SETTER(gchar*, username); -GETTER_SETTER(gchar*, features); -GETTER_SETTER(gchar*, distance); -GETTER_SETTER(gchar*, last_profile); -GETTER_SETTER(gchar*, hud); +GETTER_SETTER(ip); +GETTER_SETTER(port); +GETTER_SETTER(username); +GETTER_SETTER(features); +GETTER_SETTER(distance); +GETTER_SETTER(last_profile); +GETTER_SETTER(hud); +GETTER_SETTER(hide); static void mcpil_config_set_property(GObject* obj, guint prop_id, const GValue* value, GParamSpec* pspec) { diff --git a/src/helpers.c b/src/helpers.c index 07e9310..2652c32 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #define _GNU_SOURCE /* Required for asprintf */ @@ -48,16 +47,15 @@ int get_features() char* buff; FILE* file; - buff_sz = 48; - buff = (char*)malloc((int)buff_sz + 1); - buff[0] = 0x00; file = fopen("/opt/minecraft-pi-reborn-client/available-feature-flags", "r"); - if (file == NULL) { - free(buff); return -1; } + + buff_sz = 48; + buff = (char*)malloc((int)buff_sz + 1); + buff[0] = 0x00; while ((sz = getline(&buff, &buff_sz, file)) > 0) { FEAT_BOOL(i) = (void*)(intptr_t)(buff[0] == 'T'); @@ -66,6 +64,7 @@ int get_features() FEAT_PTR(i) = strdup(buff + offset); i++; } + free(buff); fclose(file); return i; } diff --git a/src/include/config.h b/src/include/config.h index 1820bc0..408ad44 100644 --- a/src/include/config.h +++ b/src/include/config.h @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #ifndef CONFIG_H @@ -37,22 +36,37 @@ G_BEGIN_DECLS #define VALID_JSON_ARGS(dst, name, parent) \ (parent.node != NULL || dst != NULL || name != NULL || JSON_NODE_HOLDS_OBJECT(parent.node) || parent.obj == NULL) -#define GETTER(type, name) type mcpil_config_get_ ## name (MCPILConfig* self) \ +#define GETTER(name) gchar* mcpil_config_get_ ## name (MCPILConfig* self) \ { \ MCPILConfigPrivate* private; \ private = MCPIL_CONFIG_PRIVATE(self); \ return private->name; \ } -#define SETTER(type, name) void mcpil_config_set_ ## name (MCPILConfig* self, const type name) \ +#define SETTER(name) void mcpil_config_set_ ## name (MCPILConfig* self, const gchar* name) \ { \ MCPILConfigPrivate* private; \ private = MCPIL_CONFIG_PRIVATE(self); \ - private->name = g_strdup((type)name); \ + private->name = g_strdup((gchar*)name); \ return; \ } -#define GETTER_SETTER(type, name) GETTER(type, name); SETTER(type, name); +#define GETTER_SETTER(name) GETTER(name); SETTER(name); +#define GETTER_SETTER_PROTO(name) \ +gchar* mcpil_config_get_ ## name (MCPILConfig* self) \ +void mcpil_config_set_ ## name (MCPILConfig* self, const gchar* name); + +#define MCPIL_GLIB_PROPERTY(id, name, description, prop) \ + pspec = g_param_spec_string(id, name, description, NULL, G_PARAM_READWRITE); \ + g_object_class_install_property(gobject_class, prop, pspec); + +#define MCPIL_SET_DEFAULT(name, value) \ + default_##name = mcpil_config_get_##name(config); \ + if (default_##name == NULL) \ + { \ + default_##name = value; \ + mcpil_config_set_##name(config, default_##name); \ + } typedef struct MCPILConfigPrivate MCPILConfigPrivate; @@ -75,8 +89,9 @@ void mcpil_config_set_port(MCPILConfig* self, const gchar* port); void mcpil_config_set_username(MCPILConfig* self, const gchar* username); void mcpil_config_set_features(MCPILConfig* self, const gchar* features); void mcpil_config_set_distance(MCPILConfig* self, const gchar* distance); -void mcpil_config_set_last_profile(MCPILConfig* self, const gchar* profile); +void mcpil_config_set_last_profile(MCPILConfig* self, const gchar* last_profile); void mcpil_config_set_hud(MCPILConfig* self, const gchar* hud); +void mcpil_config_set_hide(MCPILConfig* self, const gchar* hide); gchar* mcpil_config_get_ip(MCPILConfig* self); gchar* mcpil_config_get_port(MCPILConfig* self); @@ -85,6 +100,7 @@ gchar* mcpil_config_get_features(MCPILConfig* self); gchar* mcpil_config_get_distance(MCPILConfig* self); gchar* mcpil_config_get_last_profile(MCPILConfig* self); gchar* mcpil_config_get_hud(MCPILConfig* self); +gchar* mcpil_config_get_hide(MCPILConfig* self); int mcpil_config_save(MCPILConfig* self); diff --git a/src/include/mcpil.h b/src/include/mcpil.h index 25a4b33..ecf2eec 100644 --- a/src/include/mcpil.h +++ b/src/include/mcpil.h @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #ifndef MCPIL_H @@ -27,11 +26,6 @@ #include #include -#define GMCPIL_MAJOR 0 -#define GMCPIL_MINOR 10 -#define GMCPIL_PATCH 2 -#define GMCPIL_VERSION "v0.10.2" - #define STR(str) #str #define SAFE_ATOI(str) strtol(str ? str : "", NULL, 10) @@ -73,6 +67,7 @@ typedef struct settings_box_t GtkEntry* username_entry; GtkEntry* hud_entry; GtkComboBoxText* distance_combo; + GtkCheckButton* hide_check; char* buff; } settings_box_t; diff --git a/src/include/servers.h b/src/include/servers.h index 870b5ba..a69c76c 100644 --- a/src/include/servers.h +++ b/src/include/servers.h @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #ifndef SERVERS_H diff --git a/src/include/splashes.h b/src/include/splashes.h index 751c4b7..16f8acd 100644 --- a/src/include/splashes.h +++ b/src/include/splashes.h @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #ifndef SPLASHES_H diff --git a/src/mcpil.c b/src/mcpil.c index 014b34c..1fe3f9b 100644 --- a/src/mcpil.c +++ b/src/mcpil.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #define _GNU_SOURCE /* Required for asprintf */ @@ -63,7 +62,6 @@ int main(int argc, char* argv[]) /* Initialize */ srand(time(NULL)); - setenv("LD_PRELOAD", "/usr/lib/gmcpil/libmultiplayer.so", 1); /* This is cursed, but it works:tm: */ setenv("GTK_THEME", "Adwaita:dark", 1); diff --git a/src/mods/multiplayer.c b/src/mods/multiplayer.c index 3ed37af..1ccb202 100644 --- a/src/mods/multiplayer.c +++ b/src/mods/multiplayer.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #define _GNU_SOURCE /* Required for RTLD_NEXT */ diff --git a/src/tabs.c b/src/tabs.c index b07ec46..c2f38d2 100644 --- a/src/tabs.c +++ b/src/tabs.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * */ #define _GNU_SOURCE /* Required for asprintf */ @@ -218,6 +217,7 @@ TAB(Settings, "Settings", "Save", settings_cb, { char* default_username; char* default_distance; char* default_hud; + char* default_hide; GtkWidget* username_hbox; GtkWidget* username_label; GtkWidget* username_entry; @@ -227,25 +227,13 @@ TAB(Settings, "Settings", "Save", settings_cb, { GtkWidget* hud_hbox; GtkWidget* hud_label; GtkWidget* hud_entry; + GtkWidget* hide_hbox; + GtkWidget* hide_check; - default_distance = mcpil_config_get_distance(config); - default_username = mcpil_config_get_username(config); - default_hud = mcpil_config_get_hud(config); - if (default_distance == NULL) - { - default_distance = "Normal"; - mcpil_config_set_distance(config, default_distance); - } - if (default_username == NULL) - { - default_username = "StevePi"; - mcpil_config_set_username(config, default_username); - } - if (default_hud == NULL) - { - default_hud = "simple,fps"; - mcpil_config_set_hud(config, default_hud); - } + MCPIL_SET_DEFAULT(distance, "Normal"); + MCPIL_SET_DEFAULT(username, "StevePi"); + MCPIL_SET_DEFAULT(hud, "simple,fps"); + MCPIL_SET_DEFAULT(hide, "TRUE"); distance_int = get_distance(default_distance); @@ -269,6 +257,11 @@ TAB(Settings, "Settings", "Save", settings_cb, { hud_entry = gtk_entry_new_with_buffer(gtk_entry_buffer_new(default_hud, strlen(default_hud))); gtk_entry_set_width_chars(GTK_ENTRY(hud_entry), 25); + hide_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + hide_check = gtk_check_button_new_with_label("Hide launcher"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_check), default_hide[0] == 'T'); + gtk_widget_set_size_request(hide_check, -1, 32); // To match rest of input widgets + gtk_box_pack_start(GTK_BOX(username_hbox), username_label, FALSE, FALSE, 10); gtk_box_pack_end(GTK_BOX(username_hbox), username_entry, FALSE, FALSE, 10); @@ -278,13 +271,17 @@ TAB(Settings, "Settings", "Save", settings_cb, { gtk_box_pack_start(GTK_BOX(hud_hbox), hud_label, FALSE, FALSE, 10); gtk_box_pack_end(GTK_BOX(hud_hbox), hud_entry, FALSE, FALSE, 10); + gtk_box_pack_end(GTK_BOX(hide_hbox), hide_check, FALSE, FALSE, 10); + gtk_box_pack_start(GTK_BOX(tab), username_hbox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(tab), distance_hbox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(tab), hud_hbox, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(tab), hide_hbox, FALSE, FALSE, 0); settings_box.username_entry = GTK_ENTRY(username_entry); settings_box.distance_combo = GTK_COMBO_BOX_TEXT(distance_combo); settings_box.hud_entry = GTK_ENTRY(hud_entry); + settings_box.hide_check = GTK_CHECK_BUTTON(hide_check); setenv("MCPI_USERNAME", default_username, 1); setenv("MCPI_RENDER_DISTANCE", distances[distance_int], 1);