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>
|
2021-09-02 17:33:03 +00:00
|
|
|
#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"
|
2021-09-02 17:33:03 +00:00
|
|
|
#include "tier0/threadtools.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();
|
2021-09-02 17:33:03 +00:00
|
|
|
|
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)
|
2021-09-02 17:33:03 +00:00
|
|
|
{
|
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) );
|
2021-09-02 17:33:03 +00:00
|
|
|
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()
|
2021-09-02 17:33:03 +00:00
|
|
|
{
|
2022-09-05 09:54:41 +00:00
|
|
|
// Msg( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult\n" );
|
2021-09-02 17:33:03 +00:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:19:53 +00:00
|
|
|
DLL_EXPORT void Java_com_valvesoftware_ValveActivity2_setArgs(JNIEnv *env, jclass *clazz, jstring str)
|
2021-09-02 17:33:03 +00:00
|
|
|
{
|
|
|
|
strncpy( java_args, env->GetStringUTFChars(str, NULL), sizeof java_args );
|
|
|
|
}
|
|
|
|
|
2022-08-15 19:14:09 +00:00
|
|
|
void SetLauncherArgs()
|
|
|
|
{
|
2021-09-02 17:33:03 +00:00
|
|
|
#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, " ");
|
|
|
|
}
|
2021-09-02 17:33:03 +00:00
|
|
|
|
2022-01-19 15:59:42 +00:00
|
|
|
D("-fullscreen");
|
2021-09-02 17:33:03 +00:00
|
|
|
D("-nosteam");
|
|
|
|
D("-insecure");
|
2022-08-15 19:14:09 +00:00
|
|
|
|
|
|
|
#undef A
|
|
|
|
#undef D
|
2021-09-02 17:33:03 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2022-09-17 00:01:26 +00:00
|
|
|
char prop[1024];
|
2022-09-05 09:54:41 +00:00
|
|
|
|
2022-09-17 00:01:26 +00:00
|
|
|
char strValue[64];
|
|
|
|
memset (strValue, 0, 64);
|
|
|
|
snprintf(prop, sizeof(prop), "getprop %s", name);
|
|
|
|
FILE *fp = NULL;
|
|
|
|
fp = popen(prop, "r");
|
|
|
|
if (!fp) return;
|
|
|
|
|
|
|
|
fgets(strValue, sizeof(strValue), fp);
|
|
|
|
pclose(fp);
|
|
|
|
fp = NULL;
|
|
|
|
|
|
|
|
Msg("prop %s=%s", name, strValue);
|
2022-09-05 09:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-19 20:19:53 +00:00
|
|
|
DLL_EXPORT int LauncherMainAndroid( int argc, char **argv )
|
2021-09-02 17:33:03 +00:00
|
|
|
{
|
2022-06-19 14:42:55 +00:00
|
|
|
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");
|
2022-09-17 00:01:26 +00:00
|
|
|
android_property_print("ro.product.device");
|
|
|
|
android_property_print("ro.product.manufacturer");
|
|
|
|
android_property_print("ro.product.model");
|
|
|
|
android_property_print("ro.product.name");
|
2021-09-02 17:33:03 +00:00
|
|
|
|
2022-08-15 19:14:09 +00:00
|
|
|
InitCrashHandler();
|
2021-09-02 17:33:03 +00:00
|
|
|
SetLauncherArgs();
|
|
|
|
|
2021-10-09 12:22:16 +00:00
|
|
|
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
|
2021-09-02 17:33:03 +00:00
|
|
|
DeclareCurrentThreadIsMainThread(); // Init thread propertly on Android
|
|
|
|
|
|
|
|
return LauncherMain(iLastArgs, LauncherArgv);
|
|
|
|
}
|