diff --git a/Makefile b/Makefile index 8a9630e..9e4f632 100644 --- a/Makefile +++ b/Makefile @@ -21,18 +21,18 @@ # ifdef USE_CLANG +ifeq ($(origin CC),default) CC:=clang -ARM_CC:=clang -target arm-linux-gnueabihf +endif +STRIP?=llvm-strip LDFLAGS:=-fuse-ld=lld -STRIP:=llvm-strip -ARM_STRIP:=${STRIP} ARCH:=$(shell $(CC) -dumpmachine | grep -Eo "arm|aarch|86|x86_64") else +ifeq ($(origin CC),default) CC:=gcc -ARM_CC:=arm-linux-gnueabihf-gcc +endif +STRIP?=strip LDFLAGS:= -STRIP:=strip -ARM_STRIP:=arm-linux-gnueabihf-strip ARCH:=$(shell $(CC) -print-multiarch | grep -Eo "arm|aarch|86|x86_64") endif @@ -40,7 +40,7 @@ VERSION:=0.12.0 OBJS:=$(patsubst %,build/%.o,mcpil config features play servers) -CFLAGS:=-DGMCPIL_VERSION=\"v$(VERSION)\" -I./src/include -Wall -Wno-address-of-packed-member -Wno-pointer-to-int-cast -Wno-unused-result +CFLAGS+=-DGMCPIL_VERSION=\"v$(VERSION)\" -I./src/include -Wall -Wno-address-of-packed-member -Wno-pointer-to-int-cast -Wno-unused-result CFLAGS+=$(shell pkg-config --cflags gtk+-3.0 json-glib-1.0) LDFLAGS+=-Wl,--no-undefined $(shell pkg-config --libs gtk+-3.0 json-glib-1.0) diff --git a/res/doc/gmcpil/CHANGELOG.txt b/res/doc/gmcpil/CHANGELOG.txt index f6633bd..9d08595 100644 --- a/res/doc/gmcpil/CHANGELOG.txt +++ b/res/doc/gmcpil/CHANGELOG.txt @@ -1,3 +1,7 @@ +v0.12.0: + + New, fancy GUI. + + Lots of "refactoring". + v0.11.1: + Internal code changes. + First official amd64 build. diff --git a/screenshot.png b/screenshot.png index b2363d7..2df2387 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/src/config.c b/src/config.c index 49c12ac..62da6f9 100644 --- a/src/config.c +++ b/src/config.c @@ -20,6 +20,8 @@ * */ +#define _GNU_SOURCE /* Required for asprintf */ + #include #include @@ -35,6 +37,7 @@ struct __attribute__((packed)) GMCPILConfigPrivate gchar* last_profile; gchar* hud; gchar* hide; + gchar* last_featc; gchar* filename; }; @@ -47,6 +50,7 @@ enum PROP_LAST_PROFILE, PROP_HUD, PROP_HIDE, + PROP_LAST_FEATC, PROP_LAST }; @@ -72,6 +76,7 @@ static void gmcpil_config_class_init(GMCPILConfigClass* klass) GMCPIL_GLIB_PROPERTY("last_profile", "Last profile", "Last selected profile", PROP_LAST_PROFILE); GMCPIL_GLIB_PROPERTY("hud", "Gallium HUD", "Gallium HUD options", PROP_HUD); GMCPIL_GLIB_PROPERTY("hide", "Hide launcher", "Hide launcher on launch", PROP_HIDE); + GMCPIL_GLIB_PROPERTY("last_featc", "Last feature count", "Last MCPI-Reborn feature count", PROP_LAST_FEATC); return; } @@ -112,9 +117,10 @@ static void gmcpil_config_finalize(GObject* obj) GMCPIL_GETTER_SETTER(username); GMCPIL_GETTER_SETTER(features); GMCPIL_GETTER_SETTER(distance); -GMCPIL_GETTER_SETTER(last_profile); +GMCPIL_INT_GETTER_SETTER(last_profile); GMCPIL_GETTER_SETTER(hud); GMCPIL_GETTER_SETTER(hide); +GMCPIL_INT_GETTER_SETTER(last_featc); static void gmcpil_config_set_property(GObject* obj, guint prop_id, const GValue* value, GParamSpec* pspec) { diff --git a/src/features.c b/src/features.c index 96beaa2..649994a 100644 --- a/src/features.c +++ b/src/features.c @@ -67,9 +67,9 @@ static int get_features() static int set_feature_envs(int feat) { int i = 0; - static int sz[3] = {1, 1, 1}; - static int len[3] = {0, 0, 0}; - static int tmp[3] = {0, 0, 0}; + int sz[3] = {1, 1, 1}; + int len[3] = {0, 0, 0}; + int tmp[3] = {0, 0, 0}; while (i < 3) { @@ -78,16 +78,13 @@ static int set_feature_envs(int feat) i++; continue; } - if (i == 2) + if (i == 2 && (FEAT_CMP(feat, "Fancy Graphics") + || FEAT_CMP(feat, "Smooth Lighting") + || FEAT_CMP(feat, "Animated Water") + || FEAT_CMP(feat, "Disable gui_blocks Atlas"))) { - if (FEAT_CMP(feat, "Fancy Graphics") - || FEAT_CMP(feat, "Smooth Lighting") - || FEAT_CMP(feat, "Animated Water") - || FEAT_CMP(feat, "Disable gui_blocks Atlas")) - { - i++; - continue; - } + i++; + continue; } if (FEAT_INT(feat) == TRUE || (i >= 2 && i <= 3 && FEAT_CMP(feat, "Force Mob Spawning"))) { @@ -178,6 +175,7 @@ static void toggle_cb(__attribute__((unused)) GtkWidget* check, void* udata) TAB(Features, features_cb, { int i = 0; int last_profile; + int last_featc; char* tmp; char* features_buff; GtkWidget* feature_check; @@ -187,6 +185,8 @@ TAB(Features, features_cb, { featc = 0; featc = get_features(); + last_featc = gmcpil_config_get_last_featc(config); + last_profile = gmcpil_config_get_last_profile(config); features_envs[1] = (char*)malloc(1); features_envs[2] = (char*)malloc(1); @@ -202,7 +202,7 @@ TAB(Features, features_cb, { if (features_buff != NULL) { i = 0; - while (i < featc) + while (i < last_featc) { FEAT_BOOL(i) = FALSE; i++; @@ -210,7 +210,7 @@ TAB(Features, features_cb, { i = 0; tmp = strtok(features_buff, "|"); - while (tmp != NULL && i < featc) + while (tmp != NULL && i < last_featc) { feature = get_feature(tmp); if (feature != NULL) @@ -244,8 +244,8 @@ TAB(Features, features_cb, { } features_cb(NULL, (void*)TRUE); + gmcpil_config_set_last_featc(config, featc); gmcpil_config_set_features(config, features_envs[4]); - last_profile = SAFE_ATOI(gmcpil_config_get_last_profile(config)); setenv("MCPI_FEATURE_FLAGS", features_envs[last_profile], 1); gtk_container_add(GTK_CONTAINER(scroll), vbox); gtk_box_pack_start(GTK_BOX(tab), scroll, TRUE, TRUE, 0); diff --git a/src/include/config.h b/src/include/config.h index 3ba24ef..867d02f 100644 --- a/src/include/config.h +++ b/src/include/config.h @@ -35,6 +35,7 @@ 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 SAFE_ATOI(str) strtol(str ? str : "", NULL, 10) #define GMCPIL_GETTER(name) gchar* gmcpil_config_get_ ## name (GMCPILConfig* self) \ { \ @@ -51,7 +52,26 @@ G_BEGIN_DECLS return; \ } +#define GMCPIL_INT_GETTER(name) gint gmcpil_config_get_ ## name (GMCPILConfig* self) \ +{ \ + GMCPILConfigPrivate* private; \ + private = GMCPIL_CONFIG_PRIVATE(self); \ + return SAFE_ATOI(private->name); \ +} + +#define GMCPIL_INT_SETTER(name) void gmcpil_config_set_ ## name (GMCPILConfig* self, const gint name) \ +{ \ + char* tmp; \ + GMCPILConfigPrivate* private; \ + asprintf(&tmp, "%i", name); \ + private = GMCPIL_CONFIG_PRIVATE(self); \ + private->name = g_strdup((gchar*)tmp); \ + free(tmp); \ + return; \ +} + #define GMCPIL_GETTER_SETTER(name) GMCPIL_GETTER(name); GMCPIL_SETTER(name); +#define GMCPIL_INT_GETTER_SETTER(name) GMCPIL_INT_GETTER(name); GMCPIL_INT_SETTER(name); #define GMCPIL_GLIB_PROPERTY(id, name, description, prop) \ pspec = g_param_spec_string(id, name, description, NULL, G_PARAM_READWRITE); \ @@ -84,16 +104,18 @@ GMCPILConfig* gmcpil_config_new(gchar* filename); void gmcpil_config_set_username(GMCPILConfig* self, const gchar* username); void gmcpil_config_set_features(GMCPILConfig* self, const gchar* features); void gmcpil_config_set_distance(GMCPILConfig* self, const gchar* distance); -void gmcpil_config_set_last_profile(GMCPILConfig* self, const gchar* last_profile); +void gmcpil_config_set_last_profile(GMCPILConfig* self, const gint last_profile); void gmcpil_config_set_hud(GMCPILConfig* self, const gchar* hud); void gmcpil_config_set_hide(GMCPILConfig* self, const gchar* hide); +void gmcpil_config_set_last_featc(GMCPILConfig* self, const gint last_featc); gchar* gmcpil_config_get_username(GMCPILConfig* self); gchar* gmcpil_config_get_features(GMCPILConfig* self); gchar* gmcpil_config_get_distance(GMCPILConfig* self); -gchar* gmcpil_config_get_last_profile(GMCPILConfig* self); +gint gmcpil_config_get_last_profile(GMCPILConfig* self); gchar* gmcpil_config_get_hud(GMCPILConfig* self); gchar* gmcpil_config_get_hide(GMCPILConfig* self); +gint gmcpil_config_get_last_featc(GMCPILConfig* self); int gmcpil_config_save(GMCPILConfig* self); diff --git a/src/include/mcpil.h b/src/include/mcpil.h index 7ba62ec..99d855f 100644 --- a/src/include/mcpil.h +++ b/src/include/mcpil.h @@ -27,7 +27,6 @@ #include #define STR(str) #str -#define SAFE_ATOI(str) strtol(str ? str : "", NULL, 10) #define FEAT_BOOL(i) (features[i][0]) #define FEAT_INT(i) ((int)features[i][0]) @@ -48,7 +47,6 @@ g_signal_connect(button, "clicked", G_CALLBACK(button_cb), cb_udata); \ return tab; \ } -//gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(STR(name_str))); #define GMCPIL_REPO_URL "https://github.com/MCPI-Revival/gMCPIL" #define GMCPIL_COPYRIGHT "Copyright 2021 MCPI-Revival contributors" diff --git a/src/mcpil.c b/src/mcpil.c index 0801394..7689403 100644 --- a/src/mcpil.c +++ b/src/mcpil.c @@ -91,7 +91,6 @@ void activate_cb(GtkApplication* app, __attribute__((unused)) void* udata) Play_tab(stack); Features_tab(stack); Servers_tab(stack); - //Settings_tab(stack); gtk_box_pack_start(GTK_BOX(switcher_box), switcher, TRUE, FALSE, 0); gtk_box_pack_end(GTK_BOX(switcher_box), about_button, TRUE, FALSE, 2); @@ -116,7 +115,7 @@ int main(int argc, char* argv[]) /* This is cursed, but it works:tm: */ setenv("GTK_THEME", "Adwaita:dark", 1); - asprintf(&config_path, "%s/.minecraft-pi/gmcpil.json", getenv("HOME")); + asprintf(&config_path, "%s/.gmcpil.json", getenv("HOME")); config = gmcpil_config_new(config_path); free(config_path); diff --git a/src/play.c b/src/play.c index 07b11cc..4a11d15 100644 --- a/src/play.c +++ b/src/play.c @@ -67,10 +67,9 @@ static int get_distance(char* str) return -1; } -static void settings_cb(__attribute__((unused)) GtkWidget* button, void* udata) +static void settings_cb(__attribute__((unused)) GtkWidget* button, __attribute__((unused)) void* udata) { int profile; - char tmp[2] = {0x00, 0x00}; const char* username; const char* distance; const char* hud; @@ -78,11 +77,6 @@ static void settings_cb(__attribute__((unused)) GtkWidget* button, void* udata) GtkEntryBuffer* username_buff; GtkEntryBuffer* hud_buff; - if ((int)udata == TRUE) - { - goto profile; - } - username_buff = gtk_entry_get_buffer(GTK_ENTRY(settings_box.username_entry)); hud_buff = gtk_entry_get_buffer(GTK_ENTRY(settings_box.hud_entry)); @@ -106,12 +100,10 @@ static void settings_cb(__attribute__((unused)) GtkWidget* button, void* udata) gmcpil_config_set_hide(config, "FALSE"); } -profile: profile = gtk_combo_box_get_active(GTK_COMBO_BOX(settings_box.profile_combo)); setenv("MCPI_FEATURE_FLAGS", features_envs[profile], 1); - tmp[0] = profile + 0x30; - gmcpil_config_set_last_profile(config, tmp); + gmcpil_config_set_last_profile(config, profile); gmcpil_config_save(config); return; } @@ -129,7 +121,7 @@ static void launch_cb(__attribute__((unused)) GtkWidget* button, __attribute__(( GPid pid; GError* err = NULL; - settings_cb(NULL, (void*)(intptr_t)TRUE); + settings_cb(NULL, NULL); g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &err); if (err != NULL) @@ -226,7 +218,7 @@ TAB(Play, settings_cb, { profile_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); profile_label = gtk_label_new("Profile"); profile_combo = gtk_combo_box_text_new(); - last_profile = SAFE_ATOI(gmcpil_config_get_last_profile(config)); + last_profile = gmcpil_config_get_last_profile(config); while (i < 5) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(profile_combo), profile_names[i]);