Initial android support (#17)

* Upload Android armv7 libs

* Fix debug build

* utlvector: fix undefined behavior

* wscript: add --use-ccache option

* wscript: store ccache in a separate directory

* Propertly use gl4es

* fontconfig: fix font detection

* [android]remove fontconfig dependency

* Add build guide for other platforms

Co-authored-by: JusicP <slender87844@gmail.com>
Co-authored-by: nillerusr <nillerusr@users.noreply.github.com>
This commit is contained in:
nillerusr
2021-09-02 20:33:03 +03:00
committed by GitHub
parent 2a490d398c
commit 2c6669f5e3
57 changed files with 524 additions and 111 deletions

145
launcher/android.cpp Normal file
View File

@@ -0,0 +1,145 @@
#ifdef ANDROID
#include <android/log.h>
#include <jni.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <dlfcn.h>
#include "tier0/threadtools.h"
char *LauncherArgv[512];
char java_args[4096];
int iLastArgs = 0;
#define TAG "SRCENG"
#define PRIO ANDROID_LOG_DEBUG
#define LogPrintf(...) do { __android_log_print(PRIO, TAG, __VA_ARGS__); printf( __VA_ARGS__); } while( 0 );
#define DLLEXPORT extern "C" __attribute__((visibility("default")))
DLLEXPORT void Java_com_valvesoftware_ValveActivity2_setDataDirectoryPath(JNIEnv *env, jclass *clazz, jstring path)
{
setenv( "APP_DATA_PATH", env->GetStringUTFChars(path, NULL), 1);
LogPrintf( "Java_com_valvesoftware_ValveActivity2_setDataDirectoryPath: %s", getenv("APP_DATA_PATH") );
}
DLLEXPORT void Java_com_valvesoftware_ValveActivity2_setGameDirectoryPath(JNIEnv *env, jclass *clazz, jstring path)
{
LogPrintf( "Java_com_valvesoftware_ValveActivity2_setGameDirectoryPath" );
setenv( "VALVE_GAME_PATH", env->GetStringUTFChars(path, NULL), 1 );
}
DLLEXPORT int Java_com_valvesoftware_ValveActivity2_setenv(JNIEnv *jenv, jclass *jclass, jstring env, jstring value, jint over)
{
LogPrintf( "Java_com_valvesoftware_ValveActivity2_setenv %s=%s", jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL) );
return setenv( jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL), over );
}
DLLEXPORT void Java_com_valvesoftware_ValveActivity2_nativeOnActivityResult()
{
LogPrintf( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult" );
}
void parseArgs( char *args )
{
char *pch;
pch = strtok (args," ");
while (pch != NULL)
{
LauncherArgv[iLastArgs++] = pch;
pch = strtok (NULL, " ");
}
}
DLLEXPORT void Java_com_valvesoftware_ValveActivity2_setArgs(JNIEnv *env, jclass *clazz, jstring str)
{
strncpy( java_args, env->GetStringUTFChars(str, NULL), sizeof java_args );
}
DLLEXPORT int LauncherMain( int argc, char **argv );
#define A(a,b) LauncherArgv[iLastArgs++] = (char*)a; \
LauncherArgv[iLastArgs++] = (char*)b
#define D(a) LauncherArgv[iLastArgs++] = (char*)a
void SetLauncherArgs()
{
static char binPath[2048];
snprintf(binPath, sizeof binPath, "%s/hl2_linux", getenv("APP_DATA_PATH") );
LogPrintf(binPath);
D(binPath);
parseArgs(java_args);
A("-game", "hl2");
D("-window");
D("-nosteam");
D("-insecure");
}
static void *lgles;
typedef void (*t_set_getprocaddress)(void *(*new_proc_address)(const char *));
t_set_getprocaddress gl4es_set_getprocaddress;
typedef void *(*t_eglGetProcAddress)( const char * );
t_eglGetProcAddress eglGetProcAddress;
void *GetProcAddress( const char *procname )
{
void *result = dlsym(lgles, procname);
if(result)
return result;
else
return eglGetProcAddress(procname);
}
DLLEXPORT int LauncherMainAndroid( int argc, char **argv )
{
SetLauncherArgs();
void *lgl4es = dlopen("libgl4es.so", 0);
if( !lgl4es )
{
LogPrintf("Failed to dlopen library libgl4es.so: %s\n", dlerror());
return 1;
}
void *lEGL = dlopen("libEGL.so", 0);
if( !lEGL )
{
LogPrintf("Failed to dlopen library libEGL.so: %s\n", dlerror());
return 1;
}
lgles = dlopen("libGLESv2.so", 0);
if( !lgles )
{
LogPrintf("Failed to dlopen library libGLESv2.so: %s\n", dlerror());
return 1;
}
gl4es_set_getprocaddress = (t_set_getprocaddress)dlsym(lgl4es, "set_getprocaddress");
eglGetProcAddress = (t_eglGetProcAddress)dlsym(lEGL, "eglGetProcAddress");
if( gl4es_set_getprocaddress && eglGetProcAddress )
{
gl4es_set_getprocaddress( &GetProcAddress );
}
else
{
LogPrintf("Failed to call set_getprocaddress\n");
return 1;
}
DeclareCurrentThreadIsMainThread(); // Init thread propertly on Android
return LauncherMain(iLastArgs, LauncherArgv);
}
#endif

View File

@@ -82,6 +82,11 @@ int MessageBox( HWND hWnd, const char *message, const char *header, unsigned uTy
#define RELAUNCH_FILE "/tmp/hl2_relaunch"
#endif
#if defined ( ANDROID )
#include <android/log.h>
#include "jni.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
@@ -248,7 +253,11 @@ bool GetExecutableName( char *out, int outSize )
//-----------------------------------------------------------------------------
char *GetBaseDirectory( void )
{
#ifdef ANDROID
return getenv("VALVE_GAME_PATH");
#else
return g_szBasedir;
#endif
}
//-----------------------------------------------------------------------------
@@ -680,8 +689,7 @@ bool CSourceAppSystemGroup::Create()
if ( !AddSystems( appSystems ) )
return false;
// This will be NULL for games that don't support VR. That's ok. Just don't load the DLL
AppModule_t sourceVRModule = LoadModule( "sourcevr" DLL_EXT_STRING );
if( sourceVRModule != APP_MODULE_INVALID )
@@ -934,7 +942,9 @@ bool GrabSourceMutex()
CRC32_ProcessBuffer( &gameCRC, (void *)pchGameParam, Q_strlen( pchGameParam ) );
CRC32_Final( &gameCRC );
#ifdef LINUX
#ifdef ANDROID
return true;
#elif defined (LINUX)
/*
* Linux
*/
@@ -1175,7 +1185,7 @@ static const char *BuildCommand()
// Output : int APIENTRY
//-----------------------------------------------------------------------------
#ifdef WIN32
extern "C" __declspec(dllexport) int LauncherMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
extern "C" __declspec(DLL_EXPORT) int LauncherMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
#else
DLL_EXPORT int LauncherMain( int argc, char **argv )
#endif
@@ -1229,7 +1239,7 @@ DLL_EXPORT int LauncherMain( int argc, char **argv )
{
return -1;
}
const char *filename;
#ifdef WIN32
CommandLine()->CreateCmdLine( IsPC() ? VCRHook_GetCommandLine() : lpCmdLine );
@@ -1448,6 +1458,7 @@ DLL_EXPORT int LauncherMain( int argc, char **argv )
// Figure out the directory the executable is running from
// and make that be the current working directory
_chdir( GetBaseDirectory() );
g_LeakDump.m_bCheckLeaks = CommandLine()->CheckParm( "-leakcheck" ) ? true : false;

View File

@@ -19,6 +19,7 @@ def build(bld):
'../public/filesystem_init.cpp',
'launcher.cpp',
'reslistgenerator.cpp',
'android.cpp'
]
includes = [