diff --git a/src/game/player_palette.c b/src/game/player_palette.c index 65d019c3..55e10955 100644 --- a/src/game/player_palette.c +++ b/src/game/player_palette.c @@ -53,6 +53,39 @@ static u8 read_value(const char* data) { return MIN(strtol(data, NULL, 0), 255); } +static void player_palettes_sort_characters(void) { + struct PresetPalette charPresetPalettes[MAX_PRESET_PALETTES] = { 0 }; + u8 charPresetPaletteCount = 0; + + // copy character palettes first + for (int c = 0; c < CT_MAX; c++) { // heh, c++ + for (int i = 0; i < gPresetPaletteCount; i++) { + if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) { + charPresetPalettes[charPresetPaletteCount++] = gPresetPalettes[i]; + } + } + } + + // copy remaining palettes + for (int i = 0; i < gPresetPaletteCount; i++) { + bool isCharPalette = false; + for (int c = 0; c < CT_MAX; c++) { // heh, c++ + if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) { + isCharPalette = true; + break; + } + } + if (!isCharPalette) { + charPresetPalettes[charPresetPaletteCount++] = gPresetPalettes[i]; + } + } + + // finally, write to gPresetPalettes + for (int i = 0; i < gPresetPaletteCount; i++) { + gPresetPalettes[i] = charPresetPalettes[i]; + } +} + void player_palettes_read(const char* palettesPath, bool appendPalettes) { // construct lang path char lpath[SYS_MAX_PATH] = ""; @@ -116,36 +149,7 @@ void player_palettes_read(const char* palettesPath, bool appendPalettes) { // this should mean we are in the exe path's palette dir if (appendPalettes) { - struct PresetPalette characterPresetPalettes[MAX_PRESET_PALETTES] = { 0 }; - u8 characterPresetPaletteCount = 0; - - // copy character palettes first - for (int c = 0; c < CT_MAX; c++) { // heh, c++ - for (int i = 0; i < gPresetPaletteCount; i++) { - if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) { - characterPresetPalettes[characterPresetPaletteCount++] = gPresetPalettes[i]; - } - } - } - - // copy remaining palettes - for (int i = 0; i < gPresetPaletteCount; i++) { - bool isCharacterPalette = false; - for (int c = 0; c < CT_MAX; c++) { // heh, c++ - if (!strcmp(gPresetPalettes[i].name, gCharacters[c].name)) { - isCharacterPalette = true; - break; - } - } - if (!isCharacterPalette) { - characterPresetPalettes[characterPresetPaletteCount++] = gPresetPalettes[i]; - } - } - - // finally, write to gPresetPalettes - for (int i = 0; i < gPresetPaletteCount; i++) { - gPresetPalettes[i] = characterPresetPalettes[i]; - } + player_palettes_sort_characters(); } } diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index e705ce7c..b314c478 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -1750,10 +1750,11 @@ char* remove_color_codes(const char* str) { char* result = strdup(str); char* startColor; while ((startColor = strstr(result, "\\#"))) { - char* endColor = strstr(startColor, "\\"); + char* endColor = strstr(startColor + 2, "\\"); if (endColor) { - memmove(startColor, endColor + 1, strlen(endColor)); + memmove(startColor, endColor + 1, strlen(endColor + 1) + 1); } else { + *startColor = '\0'; break; } } diff --git a/src/pc/mods/mods.c b/src/pc/mods/mods.c index 0376b1ac..be37b778 100644 --- a/src/pc/mods/mods.c +++ b/src/pc/mods/mods.c @@ -174,6 +174,21 @@ void mods_activate(struct Mods* mods) { mod_cache_save(); } +static char* mods_remove_color_codes(const char* str) { + char* result = strdup(str); + char* startColor; + while ((startColor = strstr(result, "\\#"))) { + char* endColor = strstr(startColor + 2, "\\"); + if (endColor) { + memmove(startColor, endColor + 1, strlen(endColor + 1) + 1); + } else { + *startColor = '\0'; + break; + } + } + return result; +} + static void mods_sort(struct Mods* mods) { if (mods->entryCount <= 1) { return; @@ -184,11 +199,15 @@ static void mods_sort(struct Mods* mods) { struct Mod* mod = mods->entries[i]; for (s32 j = 0; j < i; ++j) { struct Mod* mod2 = mods->entries[j]; - if (strcmp(mod->name, mod2->name) < 0) { + char* name = mods_remove_color_codes(mod->name); + char* name2 = mods_remove_color_codes(mod2->name); + if (strcmp(name, name2) < 0) { mods->entries[i] = mod2; mods->entries[j] = mod; mod = mods->entries[i]; } + free(name); + free(name2); } } }