diff --git a/Natives/AppDelegate.m b/Natives/AppDelegate.m index 73fa6947..65879cf2 100644 --- a/Natives/AppDelegate.m +++ b/Natives/AppDelegate.m @@ -4,6 +4,7 @@ #import "AppDelegate.h" #import "JavaLauncher.h" +#import @interface AppDelegate () diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index 06dac9de..377e0ece 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -4,17 +4,16 @@ project(PojavLauncher) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_C_FLAGS "-x objective-c") -add_executable(PojavLauncher main.c JavaLauncher.c) +add_executable(PojavLauncher main.c log.m JavaLauncher.c) target_link_libraries(PojavLauncher "-framework UIKit" ) - set_target_properties(PojavLauncher PROPERTIES MACOSX_BUNDLE TRUE MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget MACOSX_BUNDLE_INFO_PLIST "../Info.plist") -add_library(pojavexec SHARED AppDelegate.m UILauncher.m egl_bridge_ios.m egl_bridge.c input_bridge_v3.c utils.c) +add_library(pojavexec SHARED log.m AppDelegate.m UILauncher.m egl_bridge_ios.m egl_bridge.c input_bridge_v3.c utils.c) target_link_libraries(pojavexec "-framework OpenGLES" ) diff --git a/Natives/JavaLauncher.c b/Natives/JavaLauncher.c index 84c028b1..6c333f65 100644 --- a/Natives/JavaLauncher.c +++ b/Natives/JavaLauncher.c @@ -4,12 +4,12 @@ #include #include #include -#include #include #include #include "jni.h" +#include "log.h" #include "JavaLauncher.h" // PojavLancher: fixme: are these wrong? @@ -38,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]; @@ -47,13 +47,13 @@ void append(char* s, char* c) { } int launchJVM(int argc, char *argv[]) { - printf("Beginning JVM launch\n"); + debug("Beginning JVM launch\n"); 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); @@ -66,7 +66,7 @@ int launchJVM(int argc, char *argv[]) { // Check if JVM restarts if (!started) { margv[margc++] = "/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) { @@ -92,23 +92,23 @@ int launchJVM(int argc, char *argv[]) { 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"); int targc = started ? argc : margc; - char *targv[] targv = started ? argv : margv; + char **targv = started ? argv : margv; if (!started) { started = true; diff --git a/Natives/JavaLauncher.h b/Natives/JavaLauncher.h index 145ffdae..ca7c5349 100644 --- a/Natives/JavaLauncher.h +++ b/Natives/JavaLauncher.h @@ -1,5 +1,7 @@ #pragma once +#include + static bool started = false; int launchJVM(int argc, char *argv[]); 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); +}