diff --git a/src/internal.c b/src/internal.c index 117832e..337bab3 100644 --- a/src/internal.c +++ b/src/internal.c @@ -200,7 +200,7 @@ SYMBOL_INTERNAL bool OpenGamestate(struct Game* game, struct Gamestate* gamestat PrintConsole(game, "Opening gamestate \"%s\"...", gamestate->name); char libname[1024]; snprintf(libname, 1024, "libsuperderpy-%s-%s" LIBRARY_EXTENSION, game->name, gamestate->name); - gamestate->handle = dlopen(libname, RTLD_NOW); + gamestate->handle = dlopen(AddGarbage(game, GetLibraryPath(game, libname)), RTLD_NOW); if (!gamestate->handle) { FatalError(game, false, "Error while opening gamestate \"%s\": %s", gamestate->name, dlerror()); // TODO: move out return false; @@ -407,3 +407,21 @@ SYMBOL_INTERNAL void DrawTimelines(struct Game* game) { tmp = tmp->next; } } + +SYMBOL_INTERNAL char* GetLibraryPath(struct Game* game, char* filename) { + char* result = NULL; + ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_EXENAME_PATH); + al_set_path_filename(path, filename); + if (al_filename_exists(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP))) { + result = strdup(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); + } else { + al_append_path_component(path, "gamestates"); + if (al_filename_exists(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP))) { + result = strdup(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); + } else { + result = strdup(filename); + } + } + al_destroy_path(path); + return result; +} diff --git a/src/internal.h b/src/internal.h index b5ef63f..7b58b03 100644 --- a/src/internal.h +++ b/src/internal.h @@ -86,5 +86,6 @@ bool OpenGamestate(struct Game* game, struct Gamestate* gamestate); bool LinkGamestate(struct Game* game, struct Gamestate* gamestate); void CloseGamestate(struct Game* game, struct Gamestate* gamestate); struct Gamestate* AllocateGamestate(struct Game* game, const char* name); +char* GetLibraryPath(struct Game* game, char* filename); #endif