#include "string.h" #include "stdio.h" #include "unistd.h" #include "libgen.h" #ifdef __APPLE__ #include #endif #ifdef __WIN32__ #include "windows.h" #else #include "dlfcn.h" #endif #if defined(__APPLE__) && defined(__MACH__) #include "TargetConditionals.h" #if TARGET_OS_IPHONE // iOS #include "SDL3/SDL_main.h" #else // macOS #endif #else // Other platforms #endif #ifndef MAX_PATH #define MAX_PATH 4096 #endif static char szLauncherPath[MAX_PATH]; static char szEnginePath[MAX_PATH]; static char szTier0Path[MAX_PATH]; static char szSteamPath[MAX_PATH]; void *pEngineLib = NULL; void *pTier0Lib = NULL; typedef void (*EngineMainFn)(int argc, char** argv); EngineMainFn pEngineMain; //extern "C" void FunnyMain( int argc, char **argv ); int main( int argc, char **argv ) { #ifdef __linux__ 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); snprintf(szSteamPath, MAX_PATH, "%s/libsteam_api.so", szLauncherPath); #endif #ifdef __APPLE__ uint32_t pathSize = sizeof(szLauncherPath); int pathResult = _NSGetExecutablePath(szLauncherPath, &pathSize); char *szLauncherPath2 = dirname(szLauncherPath); snprintf(szEnginePath, MAX_PATH, "%s/libengine.dylib", szLauncherPath2); snprintf(szTier0Path, MAX_PATH, "%s/libtier0.dylib", szLauncherPath2); #endif #ifndef __WIN32__ if ( !dlopen(szSteamPath, RTLD_NOW )) printf("Failed to open steam\n"); pTier0Lib = dlopen(szTier0Path, RTLD_LAZY | RTLD_GLOBAL); if ( !pTier0Lib ) { printf("Failed to open libtier0\n"); printf("\t%s\n",dlerror()); } pEngineLib = dlopen(szEnginePath, RTLD_NOW ); if ( !pEngineLib ) { printf("Failed to open libengine\n"); printf("\t%s\n",dlerror()); } pEngineMain = (EngineMainFn)dlsym(pEngineLib, "FunnyMain"); if ( !pEngineMain ) { printf("Symbol not found: FunnyMain\n"); } // chdir to right directory dirname(szLauncherPath); chdir(szLauncherPath); printf("%s\n",szLauncherPath); pEngineMain(argc, argv); dlclose(pEngineLib); #endif #ifdef __WIN32__ GetModuleFileNameA(NULL, szLauncherPath, MAX_PATH); dirname(szLauncherPath); snprintf(szEnginePath, MAX_PATH, "%s/engine.dll", szLauncherPath); snprintf(szTier0Path, MAX_PATH, "%s/tier0.dll", szLauncherPath); printf("%s\n", szEnginePath); pEngineLib = LoadLibraryA(szEnginePath); pEngineMain = (EngineMainFn)GetProcAddress((HMODULE)pEngineLib, "FunnyMain"); if ( !pEngineMain ) { printf("Symbol not found: FunnyMain\n"); } dirname(szLauncherPath); SetCurrentDirectoryA(szLauncherPath); pEngineMain(argc, argv); #endif //FunnyMain(argc, argv); };