From 58282f775289691e9d22a43a8ea3b4738d4272ac Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 23 Apr 2022 00:30:43 -0700 Subject: [PATCH] Sort mods list --- src/pc/mods/mods.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/pc/mods/mods.c b/src/pc/mods/mods.c index bef207ce..090d1b43 100644 --- a/src/pc/mods/mods.c +++ b/src/pc/mods/mods.c @@ -90,6 +90,25 @@ void mods_activate(struct Mods* mods) { mod_cache_save(); } +static void mods_sort(struct Mods* mods) { + if (mods->entryCount <= 1) { + return; + } + + // By default, this is the alphabetical order on name + for (s32 i = 1; i < mods->entryCount; ++i) { + 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) { + mods->entries[i] = mod2; + mods->entries[j] = mod; + mod = mods->entries[i]; + } + } + } +} + static void mods_load(struct Mods* mods, char* modsBasePath) { // generate bins dynos_generate_packs(modsBasePath); @@ -160,6 +179,9 @@ void mods_init(void) { strncat(defaultModsPath, MOD_DIRECTORY, SYS_MAX_PATH-1); mods_load(&gLocalMods, defaultModsPath); + // sort + mods_sort(&gLocalMods); + // calculate total size gLocalMods.size = 0; for (int i = 0; i < gLocalMods.entryCount; i++) {