Files
funnygame/launcher/launcher.cpp
2025-05-28 14:36:57 +03:00

51 lines
1.3 KiB
C++

#include "string.h"
#include "stdio.h"
#include "unistd.h"
#include "dlfcn.h"
#include "libgen.h"
#define MAX_PATH 4096
static char szLauncherPath[MAX_PATH];
static char szEnginePath[MAX_PATH];
static char szTier0Path[MAX_PATH];
void *pEngineLib = NULL;
void *pTier0Lib = NULL;
typedef void (*EngineMainFn)(int argc, char** argv);
EngineMainFn pEngineMain;
int main( int argc, char **argv ) {
readlink("/proc/self/exe",szLauncherPath, MAX_PATH);
dirname(szLauncherPath);
snprintf(szEnginePath, MAX_PATH, "%s/libengine.so", szLauncherPath);
snprintf(szTier0Path, MAX_PATH, "%s/libtier0.so", szLauncherPath);
printf("%s\n",szEnginePath);
printf("%s\n",szTier0Path);
pTier0Lib = dlopen(szTier0Path, RTLD_NOW | RTLD_GLOBAL);
if ( !pTier0Lib ) {
printf("Failed to open libtier0.so\n");
printf("\t%s\n",dlerror());
}
pEngineLib = dlopen(szEnginePath, RTLD_NOW | RTLD_GLOBAL);
if ( !pEngineLib ) {
printf("Failed to open libengine.so\n");
printf("\t%s\n",dlerror());
}
printf("\t%p\n",pTier0Lib);
printf("\t%p\n",pEngineLib);
pEngineMain = (EngineMainFn)dlsym(pEngineLib, "FunnyMain");
if ( !pEngineMain ) {
printf("Symbol not found: FunnyMain\n");
}
// chdir to right directory
dirname(szLauncherPath);
chdir(szLauncherPath);
pEngineMain(argc, argv);
dlclose(pEngineLib);
};