From d8f4199fe1d83b3088e010bb49ba6e2ed9da152c Mon Sep 17 00:00:00 2001 From: Hayden Date: Thu, 31 Dec 2020 22:04:37 -0500 Subject: [PATCH 1/5] Update AppDelegate.m --- Natives/AppDelegate.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Natives/AppDelegate.m b/Natives/AppDelegate.m index f562af38..3492777e 100644 --- a/Natives/AppDelegate.m +++ b/Natives/AppDelegate.m @@ -4,6 +4,7 @@ #import "AppDelegate.h" #import "JavaLauncher.h" +#import @interface AppDelegate () @@ -14,6 +15,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + NSLog(@"Hello from app launch!"); launchJVM(); return YES; From 2dc204cc5e0838e8dd03d93979e86f83329d27f0 Mon Sep 17 00:00:00 2001 From: Hayden Date: Thu, 31 Dec 2020 22:20:06 -0500 Subject: [PATCH 2/5] Test NSLogging C --- Natives/CMakeLists.txt | 2 +- Natives/JavaLauncher.c | 17 +++++++++-------- Natives/log.h | 2 ++ Natives/log.m | 10 ++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 Natives/log.m diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index fd0e20ac..468f9fe1 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -4,7 +4,7 @@ project(PojavLauncher) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_C_FLAGS "-x objective-c") -add_executable(PojavLauncher main.m AppDelegate.m JavaLauncher.c) +add_executable(PojavLauncher main.m log.m AppDelegate.m JavaLauncher.c) target_link_libraries(PojavLauncher "-framework UIKit" ) diff --git a/Natives/JavaLauncher.c b/Natives/JavaLauncher.c index 51956d68..8e0b0d9b 100644 --- a/Natives/JavaLauncher.c +++ b/Natives/JavaLauncher.c @@ -9,6 +9,7 @@ #include #include "jni.h" +#include "log.h" #include "JavaLauncher.h" // PojavLancher: fixme: are these wrong? @@ -37,7 +38,7 @@ typedef jint JLI_Launch_func(int argc, char ** argv, /* main argc, argc */ ); void append(char* s, char* c) { - printf("Appending %s\n", c); + debug("Appending %s\n", c); int len; for (len = strlen(s); c[len] != '\0'; len++) { s[len] = c[len]; @@ -46,14 +47,14 @@ void append(char* s, char* c) { } int launchJVM() { - printf("Beginning JVM launch\n"); + debug("Beginning JVM launch\n"); mkdir("/var/mobile/Documents/minecraft", 0700); char *args_path = "/var/mobile/Documents/minecraft/overrideargs.txt"; char *log_path = "/var/mobile/Documents/minecraft/latestlog.txt"; char *main_jar = "/Applications/PojavLauncher.app/launcher.jar"; - printf("Staring logging STDIO as jrelog:V\n"); + debug("Staring logging STDIO as jrelog:V\n"); // Redirect stdio to latestlog.txt FILE* logFile = fopen(log_path, "w"); int log_fd = fileno(logFile); @@ -65,7 +66,7 @@ int launchJVM() { char* margc[1000]; margc[margv++] = "/usr/lib/jvm/java-16-openjdk/bin/java"; - printf("Reading custom JVM args (overrideargs.txt)"); + debug("Reading custom JVM args (overrideargs.txt)"); char jvmargs[10000]; FILE* argsFile = fopen(args_path, "r"); if (argsFile) { @@ -87,20 +88,20 @@ int launchJVM() { void* libjli = dlopen("/usr/lib/jvm/java-16-openjdk/lib/libjli.dylib", RTLD_LAZY | RTLD_GLOBAL); if (NULL == libjli) { - printf("JLI lib = NULL: %s\n", dlerror()); + debug("JLI lib = NULL: %s\n", dlerror()); return -1; } - printf("Found JLI lib\n"); + debug("Found JLI lib\n"); JLI_Launch_func *pJLI_Launch = (JLI_Launch_func *)dlsym(libjli, "JLI_Launch"); if (NULL == pJLI_Launch) { - printf("JLI_Launch = NULL\n"); + debug("JLI_Launch = NULL\n"); return -2; } - printf("Calling JLI_Launch\n"); + debug("Calling JLI_Launch\n"); return pJLI_Launch(margc, margv, 0, NULL, // sizeof(const_jargs) / sizeof(char *), const_jargs, diff --git a/Natives/log.h b/Natives/log.h index 0c4a94d2..39bb644a 100644 --- a/Natives/log.h +++ b/Natives/log.h @@ -9,6 +9,8 @@ extern "C" { #define LOGI(...) printf(__VA_ARGS__) #define LOGD(...) printf(__VA_ARGS__) +void debug(const char *message, ...) __attribute__((format(printf, 1, 2))); + #ifdef __cplusplus } #endif diff --git a/Natives/log.m b/Natives/log.m new file mode 100644 index 00000000..ca4f51d4 --- /dev/null +++ b/Natives/log.m @@ -0,0 +1,10 @@ +#import +#import "log.h" + +void debug(const char *message,...) +{ + va_list args; + va_start(args, message); + NSLog(@"%@",[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:message] arguments:args]); + va_end(args); +} From e2bc6c08dfdc3ba1893c47931e2e360d5ff5366b Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Fri, 1 Jan 2021 10:26:44 +0700 Subject: [PATCH 3/5] bool.h -> stdbool.h --- Natives/JavaLauncher.c | 1 - Natives/JavaLauncher.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Natives/JavaLauncher.c b/Natives/JavaLauncher.c index cb65c09a..0540dedf 100644 --- a/Natives/JavaLauncher.c +++ b/Natives/JavaLauncher.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include diff --git a/Natives/JavaLauncher.h b/Natives/JavaLauncher.h index 7c3e530c..92d088fb 100644 --- a/Natives/JavaLauncher.h +++ b/Natives/JavaLauncher.h @@ -1,5 +1,7 @@ #pragma once +#include + static bool started = false; static int first_argc; From 5f2a1ed8c1a5ce71237238b4993b47934650f064 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com> Date: Fri, 1 Jan 2021 10:39:36 +0700 Subject: [PATCH 4/5] Fix the argv --- Natives/JavaLauncher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Natives/JavaLauncher.c b/Natives/JavaLauncher.c index b365b00b..21e47b93 100644 --- a/Natives/JavaLauncher.c +++ b/Natives/JavaLauncher.c @@ -109,7 +109,7 @@ int launchJVM(int argc, char *argv[]) { debug("Calling JLI_Launch\n"); int targc = started ? argc : margc; - char *targv[] targv = started ? argv : margv; + char **targv = started ? argv : margv; if (!started) { started = true; From caf79a2dfb75b9b4bb6d400fc7a1329076513a8f Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com> Date: Fri, 1 Jan 2021 10:49:33 +0700 Subject: [PATCH 5/5] Use char** --- Natives/JavaLauncher.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Natives/JavaLauncher.h b/Natives/JavaLauncher.h index 92d088fb..109a322b 100644 --- a/Natives/JavaLauncher.h +++ b/Natives/JavaLauncher.h @@ -5,7 +5,7 @@ static bool started = false; static int first_argc; -static char *first_argv[]; +static char **first_argv; int launchJVM(int argc, char *argv[]); int launchUI();