diff --git a/Natives/AppDelegate.m b/Natives/AppDelegate.m index aa2ccb40..65879cf2 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!"); // TODO callback return YES; diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index 223f735f..7fca614b 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.c AppDelegate.m UILauncher.m JavaLauncher.c) +add_executable(PojavLauncher main.c log.m AppDelegate.m UILauncher.m JavaLauncher.c) target_link_libraries(PojavLauncher "-framework UIKit" ) diff --git a/Natives/JavaLauncher.c b/Natives/JavaLauncher.c index 0540dedf..b365b00b 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(int argc, char *argv[]) { - 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); @@ -66,7 +67,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,20 +93,20 @@ 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; 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); +}