Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Commit

Permalink
Added option to hide launcher + fixes.
Browse files Browse the repository at this point in the history
 + Fixed a memory leak somewhere.
 + Fixed multiplayer on non-ARM systems.
  • Loading branch information
torralbaalla committed Jun 22, 2021
1 parent f1f85f3 commit b387c10
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 79 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions res/doc/gmcpil/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
20 changes: 16 additions & 4 deletions src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#define _GNU_SOURCE /* Required for asprintf */
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
46 changes: 18 additions & 28 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#include <stdio.h>
Expand All @@ -37,6 +36,7 @@ struct __attribute__((packed)) MCPILConfigPrivate
gchar* distance;
gchar* last_profile;
gchar* hud;
gchar* hide;
gchar* filename;
};

Expand All @@ -50,6 +50,7 @@ enum
PROP_DISTANCE,
PROP_LAST_PROFILE,
PROP_HUD,
PROP_HIDE,
PROP_LAST
};

Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down
11 changes: 5 additions & 6 deletions src/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#define _GNU_SOURCE /* Required for asprintf */
Expand Down Expand Up @@ -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');
Expand All @@ -66,6 +64,7 @@ int get_features()
FEAT_PTR(i) = strdup(buff + offset);
i++;
}
free(buff);
fclose(file);
return i;
}
Expand Down
28 changes: 22 additions & 6 deletions src/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#ifndef CONFIG_H
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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);

Expand Down
7 changes: 1 addition & 6 deletions src/include/mcpil.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#ifndef MCPIL_H
Expand All @@ -27,11 +26,6 @@
#include <gtk/gtk.h>
#include <config.h>

#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)

Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/include/servers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#ifndef SERVERS_H
Expand Down
1 change: 0 additions & 1 deletion src/include/splashes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#ifndef SPLASHES_H
Expand Down
2 changes: 0 additions & 2 deletions src/mcpil.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#define _GNU_SOURCE /* Required for asprintf */
Expand Down Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/mods/multiplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#define _GNU_SOURCE /* Required for RTLD_NEXT */
Expand Down

0 comments on commit b387c10

Please sign in to comment.