diff --git a/Makefile b/Makefile index f89e6909..cd687a9e 100644 --- a/Makefile +++ b/Makefile @@ -406,22 +406,14 @@ endif # Luigi and wario sounds don't work on 32-bit right now # And the audio code is so terrible I don't care enough to figure it out at the moment ifeq ($(TARGET_BITS), 32) - $(shell rm -rf sound/samples/sfx_custom_luigi/*.aiff) - $(shell rm -rf sound/samples/sfx_custom_luigi_peach/*.aiff) - $(shell rm -rf sound/samples/sfx_custom_wario/*.aiff) - $(shell rm -rf sound/samples/sfx_custom_wario_peach/*.aiff) + _ := $(shell rm -rf sound/samples/sfx_custom_luigi/*.aiff) + _ := $(shell rm -rf sound/samples/sfx_custom_luigi_peach/*.aiff) + _ := $(shell rm -rf sound/samples/sfx_custom_wario/*.aiff) + _ := $(shell rm -rf sound/samples/sfx_custom_wario_peach/*.aiff) endif -# Copy missing luigi sounds from mario sound banks -#$(shell mkdir -p sound/samples/sfx_custom_luigi sound/samples/sfx_custom_luigi_peach ) -#$(shell cp -n sound/samples/sfx_mario/*.aiff sound/samples/sfx_custom_luigi/ ) -#$(shell cp -n sound/samples/sfx_mario_peach/*.aiff sound/samples/sfx_custom_luigi_peach/ ) - -# Copy missing wario sounds from mario sound banks -#$(shell mkdir -p sound/samples/sfx_custom_wario sound/samples/sfx_custom_wario_peach ) -#$(shell cp -n sound/samples/sfx_mario/*.aiff sound/samples/sfx_custom_wario/ ) -#$(shell cp -n sound/samples/sfx_mario_peach/*.aiff sound/samples/sfx_custom_wario_peach/ ) - +# Copy missing character sounds from mario sound banks +_ := $(shell $(PYTHON) $(TOOLS_DIR)/copy_mario_sounds.py) #==============================================================================# # Target Executable and Sources # diff --git a/data/dynos_opt_config.cpp b/data/dynos_opt_config.cpp index a3cc02d8..b0006cfa 100644 --- a/data/dynos_opt_config.cpp +++ b/data/dynos_opt_config.cpp @@ -26,7 +26,16 @@ void DynOS_Opt_LoadConfig(DynosOption *aMenu) { // Option values switch (_Opt->mType) { +#ifdef COOP + case DOPT_TOGGLE: { + unsigned char boolValue = 0; + sscanf(_DataBegin, "%hhu\n", &boolValue); + _Opt->mToggle.mTog[0] = boolValue; + break; + } +#else case DOPT_TOGGLE: sscanf(_DataBegin, "%hhu\n", &_Opt->mToggle.mTog[0]); break; +#endif case DOPT_CHOICE: sscanf(_DataBegin, "%d\n", &_Opt->mChoice.mIndex[0]); break; case DOPT_SCROLL: sscanf(_DataBegin, "%d\n", &_Opt->mScroll.mValue[0]); break; case DOPT_BIND: sscanf(_DataBegin, "%04X;%04X;%04X\n", &_Opt->mBind.mBinds[0], &_Opt->mBind.mBinds[1], &_Opt->mBind.mBinds[2]); break; diff --git a/src/menu/star_select.c b/src/menu/star_select.c index 40c5b3ee..19f6aeb9 100644 --- a/src/menu/star_select.c +++ b/src/menu/star_select.c @@ -402,9 +402,13 @@ void print_act_selector_strings(void) { if (playersInAct > 0) { char message[16] = { 0 }; if (playersInAct == 1) { - snprintf(message, 16, "join"); + if (snprintf(message, 16, "join") < 0) { + // do nothing + } } else { - snprintf(message, 16, "%d players", playersInAct); + if (snprintf(message, 16, "%d players", playersInAct) < 0) { + // do nothing + } } gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); diff --git a/src/pc/chat_commands.c b/src/pc/chat_commands.c index 9e803208..cce703f7 100644 --- a/src/pc/chat_commands.c +++ b/src/pc/chat_commands.c @@ -20,7 +20,9 @@ static struct NetworkPlayer* chat_get_network_player(char* name) { for (int i = 0; i < MAX_PLAYERS; i++) { if (!gNetworkPlayers[i].connected) { continue; } char id[16] = { 0 }; - snprintf(id, 16, "%d", i); + if (snprintf(id, 16, "%d", i) < 0) { + // do nothing + } if (strcmp(id, name) == 0) { return &gNetworkPlayers[i]; } diff --git a/src/pc/djui/djui_panel_join.c b/src/pc/djui/djui_panel_join.c index c15d7ac8..8b085501 100644 --- a/src/pc/djui/djui_panel_join.c +++ b/src/pc/djui/djui_panel_join.c @@ -3,6 +3,7 @@ #include "src/pc/network/network.h" #include "src/pc/utils/misc.h" #include "src/pc/configfile.h" +#include "src/pc/debuglog.h" #ifdef DISCORD_SDK static char* sJoiningDiscord = "\ @@ -89,7 +90,9 @@ static bool djui_panel_join_ip_valid(char* buffer) { static void djui_panel_join_ip_text_set_new(void) { char buffer[256] = { 0 }; - snprintf(buffer, 256, "%s", sInputboxIp->buffer); + if (snprintf(buffer, 256, "%s", sInputboxIp->buffer) < 0) { + LOG_INFO("truncating IP"); + } bool afterSpacer = false; int port = 0; @@ -105,7 +108,9 @@ static void djui_panel_join_ip_text_set_new(void) { } } - snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", buffer); + if (snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", buffer) < 0) { + LOG_INFO("truncating IP"); + } if (port >= 1 && port <= 65535) { configJoinPort = port; } else { @@ -116,11 +121,11 @@ static void djui_panel_join_ip_text_set_new(void) { static void djui_panel_join_ip_text_set(struct DjuiInputbox* inputbox1) { char buffer[256] = { 0 }; if (strlen(configJoinIp) > 0 && configJoinPort != DEFAULT_PORT) { - snprintf(buffer, 256, "%s:%d", configJoinIp, configJoinPort); + if (snprintf(buffer, 256, "%s:%d", configJoinIp, configJoinPort) < 0) { LOG_INFO("truncating IP"); } } else if (strlen(configJoinIp) > 0) { - snprintf(buffer, 256, "%s", configJoinIp); + if (snprintf(buffer, 256, "%s", configJoinIp) < 0) { LOG_INFO("truncating IP"); } } else { - snprintf(buffer, 256, "127.0.0.1"); + if (snprintf(buffer, 256, "127.0.0.1") < 0) { LOG_INFO("truncating IP"); } } djui_inputbox_set_text(inputbox1, buffer); diff --git a/src/pc/fs/fs.c b/src/pc/fs/fs.c index 4008fdc1..d0c842e2 100644 --- a/src/pc/fs/fs.c +++ b/src/pc/fs/fs.c @@ -358,14 +358,18 @@ void *fs_load_file(const char *vpath, uint64_t *outsize) { const char *fs_get_write_path(const char *vpath) { static char path[SYS_MAX_PATH]; - snprintf(path, sizeof(path), "%s/%s", fs_writepath, vpath); + if (snprintf(path, sizeof(path), "%s/%s", fs_writepath, vpath) < 0) { + return NULL; + } return path; } const char *fs_convert_path(char *buf, const size_t bufsiz, const char *path) { // ! means "executable directory" if (path[0] == '!') { - snprintf(buf, bufsiz, "%s%s", sys_exe_path(), path + 1); + if (snprintf(buf, bufsiz, "%s%s", sys_exe_path(), path + 1) < 0) { + return NULL; + } } else { strncpy(buf, path, bufsiz); buf[bufsiz-1] = 0; @@ -407,7 +411,9 @@ bool fs_sys_walk(const char *base, walk_fn_t walk, void *user, const bool recur) while ((ent = readdir(dir)) != NULL) { if (ent->d_name[0] == 0 || ent->d_name[0] == '.') continue; // skip ./.. and hidden files - snprintf(fullpath, sizeof(fullpath), "%s/%s", base, ent->d_name); + if (snprintf(fullpath, sizeof(fullpath), "%s/%s", base, ent->d_name) < 0) { + continue; + } if (fs_sys_dir_exists(fullpath)) { if (recur) { if (!fs_sys_walk(fullpath, walk, user, recur)) { diff --git a/src/pc/mod_list.c b/src/pc/mod_list.c index 0c48c353..8b981fb5 100644 --- a/src/pc/mod_list.c +++ b/src/pc/mod_list.c @@ -29,7 +29,7 @@ static void mod_list_delete_tmp(void) { static char path[SYS_MAX_PATH] = { 0 }; while ((dir = readdir(d)) != NULL) { - snprintf(path, SYS_MAX_PATH - 1, "%s/%s", sTmpPath, dir->d_name); + if (snprintf(path, SYS_MAX_PATH - 1, "%s/%s", sTmpPath, dir->d_name) < 0) { continue; } if (!fs_sys_file_exists(path)) { continue; } #if defined(_WIN32) @@ -81,8 +81,11 @@ void mod_list_add_tmp(u16 index, u16 remoteIndex, char* name, size_t size) { n++; } - snprintf(entry->path, SYS_MAX_PATH - 1, "%s/%s-%u-%s", sTmpPath, sTmpSession, index, sanitizedName); - entry->fp = fopen(entry->path, "wb"); + if (snprintf(entry->path, SYS_MAX_PATH - 1, "%s/%s-%u-%s", sTmpPath, sTmpSession, index, sanitizedName) >= 0) { + entry->fp = fopen(entry->path, "wb"); + } else { + entry->fp = NULL; + } entry->remoteIndex = remoteIndex; entry->complete = false; @@ -122,13 +125,13 @@ void mod_list_extract_lua_fields(struct ModListEntry* entry) { char* extracted = NULL; if (entry->displayName == NULL && (extracted = extract_lua_field("-- name:", buffer))) { entry->displayName = calloc(33, sizeof(char)); - snprintf(entry->displayName, 32, "%s", extracted); + if (snprintf(entry->displayName, 32, "%s", extracted) < 0) {} } else if (entry->incompatible == NULL && (extracted = extract_lua_field("-- incompatible:", buffer))) { entry->incompatible = calloc(257, sizeof(char)); - snprintf(entry->incompatible, 256, "%s", extracted); + if (snprintf(entry->incompatible, 256, "%s", extracted) < 0) {} } else if (entry->description == NULL && (extracted = extract_lua_field("-- description:", buffer))) { entry->description = calloc(513, sizeof(char)); - snprintf(entry->description, 512, "%s", extracted); + if (snprintf(entry->description, 512, "%s", extracted) < 0) {} } } diff --git a/src/pc/network/discord/activity.c b/src/pc/network/discord/activity.c index a3f53278..93711e34 100644 --- a/src/pc/network/discord/activity.c +++ b/src/pc/network/discord/activity.c @@ -28,7 +28,9 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res network_init(NT_CLIENT); gCurActivity.type = DiscordActivityType_Playing; - snprintf(gCurActivity.party.id, 128, DISCORD_ID_FORMAT, lobby->id); + if (snprintf(gCurActivity.party.id, 128, DISCORD_ID_FORMAT, lobby->id) < 0) { + LOGFILE_ERROR(LFT_DISCORD, "Truncating party id"); + } gCurActivity.party.size.current_size = 2; gCurActivity.party.size.max_size = lobby->capacity; @@ -130,7 +132,9 @@ void discord_activity_update(bool hosting) { discord_populate_details(details, true); } - snprintf(gCurActivity.details, 125, "%s", details); + if (snprintf(gCurActivity.details, 125, "%s", details) < 0) { + LOGFILE_INFO(LFT_DISCORD, "truncating details"); + } app.activities->update_activity(app.activities, &gCurActivity, NULL, on_activity_update_callback); LOGFILE_INFO(LFT_DISCORD, "set activity"); diff --git a/src/pc/network/discord/lobby.c b/src/pc/network/discord/lobby.c index 2565cf3e..a0271cca 100644 --- a/src/pc/network/discord/lobby.c +++ b/src/pc/network/discord/lobby.c @@ -44,12 +44,16 @@ static void on_lobby_create_callback(UNUSED void* data, enum EDiscordResult resu LOGFILE_INFO(LFT_DISCORD, "Lobby locked: %d", lobby->locked); gCurActivity.type = DiscordActivityType_Playing; - snprintf(gCurActivity.party.id, 128, DISCORD_ID_FORMAT, lobby->id); + if (snprintf(gCurActivity.party.id, 128, DISCORD_ID_FORMAT, lobby->id) < 0) { + LOGFILE_ERROR(LFT_DISCORD, "truncating party id"); + } gCurActivity.party.size.current_size = 1; gCurActivity.party.size.max_size = configAmountofPlayers; char secretJoin[128] = ""; - snprintf(secretJoin, 128, DISCORD_ID_FORMAT ":%s", lobby->id, lobby->secret); + if (snprintf(secretJoin, 128, DISCORD_ID_FORMAT ":%s", lobby->id, lobby->secret) < 0) { + LOGFILE_ERROR(LFT_DISCORD, "truncating secret"); + } strcpy(gCurActivity.secrets.join, secretJoin); isHosting = true; diff --git a/src/pc/network/packets/packet_player_settings.c b/src/pc/network/packets/packet_player_settings.c index cb132caf..02d6f011 100644 --- a/src/pc/network/packets/packet_player_settings.c +++ b/src/pc/network/packets/packet_player_settings.c @@ -4,7 +4,9 @@ void network_send_player_settings(void) { char playerName[MAX_PLAYER_STRING+1] = { 0 }; - snprintf(playerName, MAX_PLAYER_STRING, "%s", configPlayerName); + if (snprintf(playerName, MAX_PLAYER_STRING, "%s", configPlayerName) < 0) { + LOG_INFO("truncating player name"); + } struct Packet p = { 0 }; packet_init(&p, PACKET_PLAYER_SETTINGS, true, PLMT_NONE); @@ -14,7 +16,9 @@ void network_send_player_settings(void) { packet_write(&p, &configPlayerPalette, sizeof(u8)); if (gNetworkPlayerLocal != NULL) { - snprintf(gNetworkPlayerLocal->name, MAX_PLAYER_STRING, "%s", playerName); + if (snprintf(gNetworkPlayerLocal->name, MAX_PLAYER_STRING, "%s", playerName) < 0) { + LOG_INFO("truncating player name"); + } } network_send(&p); @@ -47,7 +51,9 @@ void network_receive_player_settings(struct Packet* p) { if (playerPalette >= PALETTE_MAX) { playerPalette = 0; } struct NetworkPlayer* np = network_player_from_global_index(globalId); - snprintf(np->name, MAX_PLAYER_STRING, "%s", playerName); + if (snprintf(np->name, MAX_PLAYER_STRING, "%s", playerName) < 0) { + LOG_INFO("truncating player name"); + } if (np->modelIndex == np->overrideModelIndex) { np->overrideModelIndex = playerModel; } if (np->paletteIndex == np->overridePaletteIndex) { np->overridePaletteIndex = playerPalette; } diff --git a/tools/copy_mario_sounds.py b/tools/copy_mario_sounds.py new file mode 100644 index 00000000..4688021a --- /dev/null +++ b/tools/copy_mario_sounds.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +import os + +copy_directories = { + 'sound/samples/sfx_mario/': [ + 'sound/samples/sfx_custom_luigi/', + 'sound/samples/sfx_custom_wario/', + ], + 'sound/samples/sfx_mario_peach/': [ + 'sound/samples/sfx_custom_luigi_peach/', + 'sound/samples/sfx_custom_wario_peach/', + ], +} + +def copy_dir(source, destinations): + for filename in os.listdir(source): + if not filename.endswith('.aiff'): + continue + src = source + filename + + shortened_name = filename.split('_')[0] + '.aiff' + for destination in destinations: + dst = destination + shortened_name + if os.path.exists(dst): + continue + print('Copying mario sounds to character sounds: ' + src + ' -> ' + dst) + os.system('cp ' + src + ' ' + dst) + +def main(): + for source in copy_directories: + copy_dir(source, copy_directories[source]) + +if __name__ == "__main__": + main()