From e387b6b24b7f45c57216c237cccbca96c8708bed Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Mon, 31 Oct 2022 10:29:59 +1000 Subject: [PATCH] Fixes and quality of life changes (#213) Add the Lua Profiler to the debug menu. Prevent Mario from sleeping on the main menu. Fix IP address string corruption when saving the config file. Bring back the Discord fatal message. --- Makefile | 2 ++ src/game/hud.c | 7 +++++-- src/game/mario_actions_stationary.c | 8 +++++++- src/pc/configfile.c | 6 ++++++ src/pc/configfile.h | 3 +++ src/pc/djui/djui_interactable.c | 3 ++- src/pc/djui/djui_panel_join.c | 4 +--- src/pc/djui/djui_panel_misc.c | 7 +++++++ src/pc/network/discord/activity.c | 10 ++++------ src/pc/network/discord/discord.c | 11 +++++------ src/pc/network/network.c | 2 +- src/pc/network/packets/packet_player.c | 8 ++++++++ src/pc/network/socket/domain_res.c | 13 +------------ src/pc/network/socket/socket.c | 2 +- src/pc/network/socket/socket.h | 2 +- src/pc/pc_main.c | 8 -------- 16 files changed, 54 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index c48906cb..2555fd07 100644 --- a/Makefile +++ b/Makefile @@ -99,6 +99,8 @@ EXTRA_CFLAGS ?= EXTRA_CPP_FLAGS ?= EXTRA_CFLAGS += -Wno-format-security -Wno-trigraphs +dev:; @$(MAKE) DEBUG=1 DEVELOPMENT=1 + # COMPILER - selects the C compiler to use # gcc - uses the GNU C Compiler COMPILER = gcc diff --git a/src/game/hud.c b/src/game/hud.c index 697fb899..792401ac 100644 --- a/src/game/hud.c +++ b/src/game/hud.c @@ -534,8 +534,11 @@ void render_hud(void) { } #if defined(LUA_PROFILER) - extern void lua_profiler_update_counters(); - lua_profiler_update_counters(); + extern bool configLuaProfiler; + if (configLuaProfiler) { + extern void lua_profiler_update_counters(); + lua_profiler_update_counters(); + } #endif } } diff --git a/src/game/mario_actions_stationary.c b/src/game/mario_actions_stationary.c index a3e69ff8..6281d9c1 100644 --- a/src/game/mario_actions_stationary.c +++ b/src/game/mario_actions_stationary.c @@ -123,11 +123,17 @@ s32 act_idle(struct MarioState *m) { return TRUE; } + extern bool gDjuiInMainMenu; if (m->actionState == 3) { if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SNOW) { return set_mario_action(m, ACT_SHIVERING, 0); } else { - return set_mario_action(m, ACT_START_SLEEPING, 0); + if (!gDjuiInMainMenu) { + return set_mario_action(m, ACT_START_SLEEPING, 0); + } else { + m->actionState = 0; + m->actionTimer = 0; + } } } diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 8fea690b..b366aeb3 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -144,6 +144,9 @@ bool configDisablePopups = 0; #ifdef DEVELOPMENT bool configDisableDevPause = 1; #endif +#ifdef LUA_PROFILER +bool configLuaProfiler = 1; +#endif bool configDisableDownloadedModels = 0; unsigned int configInterpolationMode = 1; unsigned int configGamepadNumber = 0; @@ -237,6 +240,9 @@ static const struct ConfigOption options[] = { {.name = "disable_popups", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisablePopups}, #ifdef DEVELOPMENT {.name = "disable_devpause", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisableDevPause}, +#endif +#ifdef LUA_PROFILER + {.name = "lua_profiler", .type = CONFIG_TYPE_BOOL , .boolValue = &configLuaProfiler}, #endif {.name = "disable_downloaded_models", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisableDownloadedModels}, {.name = "interpolation_mode", .type = CONFIG_TYPE_UINT , .uintValue = &configInterpolationMode}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 656b1913..0c4e8035 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -101,6 +101,9 @@ extern bool configDisablePopups; #ifdef DEVELOPMENT extern bool configDisableDevPause; #endif +#ifdef LUA_PROFILER +extern bool configLuaProfiler; +#endif extern bool configDisableDownloadedModels; extern unsigned int configInterpolationMode; diff --git a/src/pc/djui/djui_interactable.c b/src/pc/djui/djui_interactable.c index 50efd47c..869ae28f 100644 --- a/src/pc/djui/djui_interactable.c +++ b/src/pc/djui/djui_interactable.c @@ -5,6 +5,7 @@ #include "src/pc/controller/controller_mouse.h" #include "src/pc/controller/controller_keyboard.h" #include "src/pc/utils/misc.h" +#include "pc/network/network.h" #include "sounds.h" #include "audio/external.h" @@ -223,7 +224,7 @@ bool djui_interactable_on_key_down(int scancode) { if (gDjuiPlayerList != NULL || gDjuiModList != NULL) { for (int i = 0; i < MAX_BINDS; i++) { - if (scancode == (int)configKeyPlayerList[i]) { + if (scancode == (int)configKeyPlayerList[i] && !gDjuiInMainMenu && gNetworkType != NT_NONE) { if (gDjuiPlayerList != NULL) { djui_base_set_visible(&gDjuiPlayerList->base, true); } diff --git a/src/pc/djui/djui_panel_join.c b/src/pc/djui/djui_panel_join.c index a57d0573..999cb107 100644 --- a/src/pc/djui/djui_panel_join.c +++ b/src/pc/djui/djui_panel_join.c @@ -118,9 +118,7 @@ static void djui_panel_join_ip_text_set_new(void) { } } - gGetHostName = buffer; - printf("gGetHostName: %s\n", gGetHostName); /* Log the value of gGetHostName. - For some reason this fixes some formatting issues? LOG_INFO isn't working at all in this file. */ + snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", buffer); if (snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", buffer) < 0) { LOG_INFO("truncating IP"); } diff --git a/src/pc/djui/djui_panel_misc.c b/src/pc/djui/djui_panel_misc.c index bdd98dc5..3a9bae7a 100644 --- a/src/pc/djui/djui_panel_misc.c +++ b/src/pc/djui/djui_panel_misc.c @@ -22,6 +22,13 @@ void djui_panel_options_debug_create(struct DjuiBase* caller) { djui_base_set_size(&checkbox2->base, 1.0f, 32); defaultBase = &checkbox2->base; +#ifdef LUA_PROFILER + struct DjuiCheckbox* checkbox3 = djui_checkbox_create(&body->base, "Lua Profiler", &configLuaProfiler); + djui_base_set_size_type(&checkbox3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&checkbox3->base, 1.0f, 32); + defaultBase = &checkbox3->base; +#endif + struct DjuiButton* button2 = djui_button_create(&body->base, "Back"); djui_base_set_size_type(&button2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size(&button2->base, 1.0f, 64); diff --git a/src/pc/network/discord/activity.c b/src/pc/network/discord/activity.c index d7d2aa48..9f6104cf 100644 --- a/src/pc/network/discord/activity.c +++ b/src/pc/network/discord/activity.c @@ -39,13 +39,11 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res discord_network_init(lobby->id); discord_activity_update(false); - if (gNetworkType == NT_CLIENT) { - if (gNetworkPlayerServer == NULL) { - network_player_connected(NPT_SERVER, 0, 0, &DEFAULT_MARIO_PALETTE, "Player"); - } - ns_discord_save_id(gNetworkPlayerServer->localIndex, lobby->owner_id); - network_send_mod_list_request(); + if (gNetworkPlayerServer == NULL) { + network_player_connected(NPT_SERVER, 0, 0, &DEFAULT_MARIO_PALETTE, "Player"); } + ns_discord_save_id(gNetworkPlayerServer->localIndex, lobby->owner_id); + network_send_mod_list_request(); gNetworkUserIds[0] = lobby->owner_id; } diff --git a/src/pc/network/discord/discord.c b/src/pc/network/discord/discord.c index a13f5e21..b5021485 100644 --- a/src/pc/network/discord/discord.c +++ b/src/pc/network/discord/discord.c @@ -21,23 +21,22 @@ static int64_t applicationId = 752700005210390568; struct DiscordApplication app = { 0 }; bool gDiscordInitialized = false; bool gDiscordFailed = false; -static int already_run = 0; +bool alreadyRun = false; static void discord_sdk_log_callback(UNUSED void* hook_data, enum EDiscordLogLevel level, const char* message) { LOGFILE_INFO(LFT_DISCORD, "callback (%d): %s", level, message); } -void discord_fatal_message(int rc) { - return; // Discord usually does this because of loss of connection to Discord +void discord_fatal_message(int rc) { // Discord usually does this because of loss of connection to Discord char errorMessage[132] = { 0 }; - snprintf(errorMessage, 132, "Discord threw an error.\nTo fix: \n1. Close the game.\n2. Restart Discord.\n3. Start the game.\nRC: %d", rc); + snprintf(errorMessage, 132, "Discord threw an error.\nTo fix, try: \n1. Close the game.\n2. Restart Discord.\n3. Start the game.\nRC: %d", rc); djui_popup_create(errorMessage, 6); } void discord_fatal(int rc) { - if (already_run == 0) { - already_run = 1; + if (!alreadyRun) { discord_fatal_message(rc); + alreadyRun = true; } if (rc != DiscordResult_Ok) { diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 4c58e1d4..1705b476 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -251,7 +251,7 @@ void network_send_to(u8 localIndex, struct Packet* p) { memcpy(&p->buffer[p->dataLength], &hash, sizeof(u32)); // redirect to server if required - if (localIndex != 0 && gNetworkType != NT_SERVER && gNetworkSystem->requireServerBroadcast) { + if (localIndex != 0 && gNetworkType != NT_SERVER && gNetworkSystem->requireServerBroadcast && gNetworkPlayerServer != NULL) { localIndex = gNetworkPlayerServer->localIndex; } diff --git a/src/pc/network/packets/packet_player.c b/src/pc/network/packets/packet_player.c index 9d3f2523..e2635d50 100644 --- a/src/pc/network/packets/packet_player.c +++ b/src/pc/network/packets/packet_player.c @@ -380,6 +380,14 @@ void network_receive_player(struct Packet* p) { network_player_disconnected(np->localIndex); } } +#else + if (m->action == ACT_DEBUG_FREE_MOVE && oldData.action != ACT_DEBUG_FREE_MOVE) { + char *playerColorString = network_get_player_text_color_string(np->localIndex); + char message[256]; + snprintf(message, 256, "%s%s\\#dcdcdc\\ entered the debug free fly state", playerColorString, np->name); + djui_popup_create(message, 1); + LOG_INFO("%s entered the debug free fly state", np->name); + } #endif } diff --git a/src/pc/network/socket/domain_res.c b/src/pc/network/socket/domain_res.c index 5a46f96f..66d42e42 100644 --- a/src/pc/network/socket/domain_res.c +++ b/src/pc/network/socket/domain_res.c @@ -10,7 +10,7 @@ #include #endif -char *gGetHostName = NULL; +char gGetHostName[MAX_CONFIG_STRING] = ""; void domain_resolution(void) { struct in_addr addr; @@ -18,10 +18,6 @@ void domain_resolution(void) { struct hostent *remoteHost; char *domainname = ""; - if (gGetHostName == NULL) { - return; - } - int i = 0; remoteHost = gethostbyname(host_name); if (remoteHost == NULL) { @@ -36,10 +32,3 @@ void domain_resolution(void) { } } } - -void save_domain(void) { - if (gGetHostName != NULL) { - snprintf(configJoinIp, 256, "%s", gGetHostName); - gGetHostName = NULL; - } -} diff --git a/src/pc/network/socket/socket.c b/src/pc/network/socket/socket.c index 2c041865..59085019 100644 --- a/src/pc/network/socket/socket.c +++ b/src/pc/network/socket/socket.c @@ -92,7 +92,7 @@ static bool ns_socket_initialize(enum NetworkType networkType) { domain_resolution(); sAddr[0].sin_addr.s_addr = inet_addr(configJoinIp); LOG_INFO("connecting to %s %u", configJoinIp, port); - save_domain(); + snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", gGetHostName); } // kick off first packet diff --git a/src/pc/network/socket/socket.h b/src/pc/network/socket/socket.h index 77765cf1..fd8cd788 100644 --- a/src/pc/network/socket/socket.h +++ b/src/pc/network/socket/socket.h @@ -10,7 +10,7 @@ #include "../network.h" extern struct NetworkSystem gNetworkSystemSocket; -extern char *gGetHostName; +extern char gGetHostName[MAX_CONFIG_STRING]; SOCKET socket_initialize(void); void socket_shutdown(SOCKET socket); diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 1fee6cdc..a7d71a78 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -1,9 +1,6 @@ #include #include #include -#ifndef _WIN32 -#include -#endif #include "sm64.h" @@ -392,11 +389,6 @@ void main_func(void) { } int main(int argc, char *argv[]) { -#ifndef _WIN32 -#ifdef SIGINT - signal(SIGINT, inthand); -#endif -#endif parse_cli_opts(argc, argv); main_func(); return 0;