source-engine/launcher/android/main.cpp

133 lines
3.4 KiB
C++
Raw Normal View History

2022-08-15 19:14:09 +00:00
/*
Copyright (C) 2022 nillerusr
2022-06-04 20:08:40 +00:00
2022-08-15 19:14:09 +00:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2021-11-16 20:46:29 +00:00
2022-08-15 19:14:09 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
2021-11-16 20:46:29 +00:00
2022-08-15 19:14:09 +00:00
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <jni.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
2021-10-09 12:22:16 +00:00
#include <SDL_hints.h>
2022-08-15 19:14:09 +00:00
#include <SDL_version.h>
#include "tier0/dbg.h"
#include "tier0/threadtools.h"
2022-09-05 09:54:41 +00:00
#include <sys/system_properties.h>
char *LauncherArgv[512];
char java_args[4096];
int iLastArgs = 0;
2022-08-15 19:14:09 +00:00
DLL_EXPORT int LauncherMain( int argc, char **argv ); // from launcher.cpp
extern void InitCrashHandler();
2022-08-19 20:19:53 +00:00
DLL_EXPORT int Java_com_valvesoftware_ValveActivity2_setenv(JNIEnv *jenv, jclass *jclass, jstring env, jstring value, jint over)
{
2022-09-05 09:54:41 +00:00
Msg( "Java_com_valvesoftware_ValveActivity2_setenv %s=%s\n", jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL) );
return setenv( jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL), over );
}
2022-08-19 20:19:53 +00:00
DLL_EXPORT void Java_com_valvesoftware_ValveActivity2_nativeOnActivityResult()
{
2022-09-05 09:54:41 +00:00
// Msg( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult\n" );
}
2022-08-19 20:19:53 +00:00
DLL_EXPORT void Java_com_valvesoftware_ValveActivity2_setArgs(JNIEnv *env, jclass *clazz, jstring str)
{
strncpy( java_args, env->GetStringUTFChars(str, NULL), sizeof java_args );
}
2022-08-15 19:14:09 +00:00
void SetLauncherArgs()
{
#define A(a,b) LauncherArgv[iLastArgs++] = (char*)a; \
LauncherArgv[iLastArgs++] = (char*)b
#define D(a) LauncherArgv[iLastArgs++] = (char*)a
static char binPath[2048];
snprintf(binPath, sizeof binPath, "%s/hl2_linux", getenv("APP_DATA_PATH") );
D(binPath);
2021-11-16 20:46:29 +00:00
D("-nouserclip");
2022-08-15 19:14:09 +00:00
char *pch;
pch = strtok (java_args," ");
while (pch != NULL)
{
LauncherArgv[iLastArgs++] = pch;
pch = strtok (NULL, " ");
}
D("-fullscreen");
D("-nosteam");
D("-insecure");
2022-08-15 19:14:09 +00:00
#undef A
#undef D
}
2022-09-05 09:54:41 +00:00
float GetTotalMemory()
{
int64_t mem = 0;
char meminfo[8196] = { 0 };
FILE *f = fopen("/proc/meminfo", "r");
if( !f )
return 0.f;
size_t size = fread(meminfo, 1, sizeof(meminfo), f);
if( !size )
return 0.f;
char *s = strstr(meminfo, "MemTotal:");
if( !s ) return 0.f;
sscanf(s+9, "%lld", &mem);
fclose(f);
return mem/1024/1024.f;
}
void android_property_print(const char *name)
{
char value[1024];
if( __system_property_get( name, value ) != 0 )
Msg("prop %s=%s\n", name, value);
}
2022-08-19 20:19:53 +00:00
DLL_EXPORT int LauncherMainAndroid( int argc, char **argv )
{
SDL_version ver;
SDL_GetVersion( &ver );
2022-08-15 19:14:09 +00:00
Msg("SDL version: %d.%d.%d rev: %s\n", (int)ver.major, (int)ver.minor, (int)ver.patch, SDL_GetRevision());
2022-09-05 09:54:41 +00:00
Msg("GetTotalMemory() = %.2f GiB\n", GetTotalMemory());
android_property_print("ro.build.version.sdk");
android_property_print("ro.product.system.device");
android_property_print("ro.product.system.manufacturer");
android_property_print("ro.product.system.model");
android_property_print("ro.product.system.name");
2022-08-15 19:14:09 +00:00
InitCrashHandler();
SetLauncherArgs();
2021-10-09 12:22:16 +00:00
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
DeclareCurrentThreadIsMainThread(); // Init thread propertly on Android
return LauncherMain(iLastArgs, LauncherArgv);
}