diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 7446915f..8d8bd82b 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -639,6 +639,7 @@ Array &DynOS_Gfx_GetActorList(); Array &DynOS_Gfx_GetPacks(); #ifdef COOP Array &DynOS_Gfx_GetPacksEnabled(); +void DynOS_Gfx_GeneratePacks(const char* directory); #endif Array DynOS_Gfx_Init(); void DynOS_Gfx_Update(); diff --git a/data/dynos_coop.c.h b/data/dynos_coop.c.h index ddeb6ba4..2b2d0246 100644 --- a/data/dynos_coop.c.h +++ b/data/dynos_coop.c.h @@ -13,6 +13,8 @@ const char* dynos_packs_get(s32 index); bool dynos_packs_get_enabled(s32 index); void dynos_packs_set_enabled(s32 index, bool value); +void dynos_generate_packs(const char* directory); + void dynos_add_actor_custom(const char *modPath, const char* geoName); const void* dynos_geolayout_get(const char *name); diff --git a/data/dynos_coop_c.cpp b/data/dynos_coop_c.cpp index c3a0e6fe..6909153e 100644 --- a/data/dynos_coop_c.cpp +++ b/data/dynos_coop_c.cpp @@ -53,6 +53,10 @@ void dynos_packs_set_enabled(s32 index, bool value) { DynOS_Gfx_GetPacksEnabled()[index] = value; } +void dynos_generate_packs(const char* directory) { + DynOS_Gfx_GeneratePacks(directory); +} + void dynos_add_actor_custom(const char *modPath, const char* geoName) { DynOS_Geo_AddActorCustom(modPath, geoName); } diff --git a/data/dynos_gfx_init.cpp b/data/dynos_gfx_init.cpp index 53a8c1be..a72c3918 100644 --- a/data/dynos_gfx_init.cpp +++ b/data/dynos_gfx_init.cpp @@ -15,6 +15,26 @@ Array &DynOS_Gfx_GetPacksEnabled() { static Array sPacksEnabled; return sPacksEnabled; } + +void DynOS_Gfx_GeneratePacks(const char* directory) { + DIR *modsDir = opendir(directory); + if (!modsDir) { return; } + + struct dirent *dir = NULL; + while ((dir = readdir(modsDir)) != NULL) { + // Skip . and .. + if (SysPath(dir->d_name) == ".") continue; + if (SysPath(dir->d_name) == "..") continue; + + // If pack folder exists, generate bins + SysPath _PackFolder = fstring("%s/%s/actors", directory, dir->d_name); + if (fs_sys_dir_exists(_PackFolder.c_str())) { + DynOS_Gfx_GeneratePack(_PackFolder); + } + } + + closedir(modsDir); +} #endif Array DynOS_Gfx_Init() { diff --git a/data/dynos_gfx_update.cpp b/data/dynos_gfx_update.cpp index 7c89cd64..9116ebe9 100644 --- a/data/dynos_gfx_update.cpp +++ b/data/dynos_gfx_update.cpp @@ -106,6 +106,9 @@ void DynOS_Gfx_Update() { #ifdef COOP Array &_Enabled = DynOS_Gfx_GetPacksEnabled(); const Array &pDynosPacks = DynOS_Gfx_GetPacks(); + while (_Enabled.Count() < pDynosPacks.Count()) { + _Enabled.Add(true); + } #else Array _Enabled; const Array &pDynosPacks = DynOS_Gfx_GetPacks(); diff --git a/data/dynos_misc.cpp b/data/dynos_misc.cpp index 37c8439d..63adefe9 100644 --- a/data/dynos_misc.cpp +++ b/data/dynos_misc.cpp @@ -342,9 +342,13 @@ static Array> sDynosCustomActors; void DynOS_Geo_AddActorCustom(const SysPath &aPackFolder, const char *aActorName) { // check for duplicates + bool isUnique = true; + s32 foundIndex = -1; for (s32 i = 0; i < DynOS_Geo_GetActorCount(); ++i) { if (!strcmp(DynOS_Geo_GetActorName(i), aActorName)) { - return; + isUnique = false; + foundIndex = i; + break; } } @@ -354,24 +358,31 @@ void DynOS_Geo_AddActorCustom(const SysPath &aPackFolder, const char *aActorName GfxData *_GfxData = DynOS_Gfx_LoadFromBinary(aPackFolder, actorName); if (!_GfxData) { + free(actorName); return; } void* geoLayout = (*(_GfxData->mGeoLayouts.end() - 1))->mData; if (!geoLayout) { + free(actorName); return; } // Add to custom actors s32 index = DynOS_Geo_GetActorCount(); - sDynosCustomActors.Add({ actorName, geoLayout }); + if (isUnique) { + sDynosCustomActors.Add({ actorName, geoLayout }); + } else { + index = foundIndex; + free(actorName); + } // Alloc and init the actors gfx list Array &pActorGfxList = DynOS_Gfx_GetActorList(); pActorGfxList.Resize(DynOS_Geo_GetActorCount()); pActorGfxList[index].mPackIndex = -1; pActorGfxList[index].mGfxData = _GfxData; - pActorGfxList[index].mGraphNode = (GraphNode *) DynOS_Geo_GetGraphNode(DynOS_Geo_GetActorLayout(index), true); + pActorGfxList[index].mGraphNode = (GraphNode *) DynOS_Geo_GetGraphNode(geoLayout, true); } s32 DynOS_Geo_GetActorCount() { diff --git a/src/pc/mods/mods.c b/src/pc/mods/mods.c index d04b9e35..b882df2d 100644 --- a/src/pc/mods/mods.c +++ b/src/pc/mods/mods.c @@ -1,6 +1,7 @@ #include #include "mods.h" #include "mods_utils.h" +#include "data/dynos_coop.c.h" #include "pc/debuglog.h" #define MOD_DIRECTORY "mods" @@ -91,6 +92,9 @@ void mods_activate(struct Mods* mods) { } static void mods_load(struct Mods* mods, char* modsBasePath) { + // generate bins + dynos_generate_packs(modsBasePath); + // sanity check if (modsBasePath == NULL) { LOG_ERROR("Trying to load from NULL path!");