Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int load_mods()
- {
- __android_log_write(ANDROID_LOG_INFO, "QuestHook", "Loading mods!");
- if (setDataDirs() != 0)
- {
- __android_log_write(ANDROID_LOG_ERROR, "QuestHook", "Unable to determine data directories.");
- return -1;
- }
- if (mkpath(modPath, 0) != 0)
- {
- __android_log_print(ANDROID_LOG_ERROR, "QuestHook", "Unable to access or create mod path at '%s'", modPath);
- return -1;
- }
- if (mkpath(modTempPath, 0) != 0)
- {
- __android_log_print(ANDROID_LOG_ERROR, "QuestHook", "Unable to access or create mod temporary path at '%s'", modTempPath);
- return -1;
- }
- struct dirent *dp;
- DIR *dir = opendir(modPath);
- while ((dp = readdir(dir)) != NULL)
- {
- if (strlen(dp->d_name) > 3 && !strcmp(dp->d_name + strlen(dp->d_name) - 3, ".so"))
- {
- char full_path[PATH_MAX];
- strcpy(full_path, modPath);
- strcat(full_path, dp->d_name);
- __android_log_print(ANDROID_LOG_INFO, "QuestHook", "Loading mod: %s", full_path);
- int infile = open(full_path, O_RDONLY);
- off_t filesize = lseek(infile, 0, SEEK_END);
- lseek(infile, 0, SEEK_SET);
- unlink(modTempPath);
- int outfile = open(modTempPath, O_CREAT | O_WRONLY);
- sendfile(outfile, infile, 0, filesize);
- close(infile);
- close(outfile);
- chmod(modTempPath, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP);
- dlopen(modTempPath, RTLD_NOW);
- }
- }
- closedir(dir);
- return 0;
- }
- __attribute__((constructor)) void lib_main()
- {
- __android_log_write(ANDROID_LOG_INFO, "QuestHook", "Welcome!");
- if (load_mods() != 0)
- {
- __android_log_write(ANDROID_LOG_ERROR, "QuestHook", "QuestHook failed to initialize, mods will not load.");
- return;
- }
- else
- {
- __android_log_write(ANDROID_LOG_INFO, "QuestHook", "Done loading mods!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement