93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
#include "string.h"
|
|
#include "stdio.h"
|
|
#include "tier0/platform.h"
|
|
#include "unistd.h"
|
|
#include "libgen.h"
|
|
|
|
#ifdef __APPLE__
|
|
#include <mach-o/dyld.h>
|
|
#endif
|
|
#ifdef __WIN32__
|
|
#include "windows.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 ) {
|
|
#ifndef STATIC_BUILD
|
|
#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);
|
|
printf("%s\n",szLauncherPath);
|
|
char *szLauncherPath2 = dirname(szLauncherPath);
|
|
printf("%s\n",szLauncherPath2);
|
|
snprintf(szEnginePath, MAX_PATH, "%s/libengine.dylib", szLauncherPath2);
|
|
snprintf(szTier0Path, MAX_PATH, "%s/libtier0.dylib", szLauncherPath2);
|
|
#endif
|
|
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_LAZY | RTLD_GLOBAL);
|
|
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);
|
|
|
|
pEngineMain(argc, argv);
|
|
dlclose(pEngineLib);
|
|
#else
|
|
#ifdef __WIN32__
|
|
GetModuleFileNameA(NULL, szLauncherPath, MAX_PATH);
|
|
dirname(szLauncherPath);
|
|
SetCurrentDirectoryA(szLauncherPath);
|
|
#endif
|
|
FunnyMain(argc, argv);
|
|
#endif
|
|
};
|