Advertisement
Sc2ad

old modloader

Oct 15th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 KB | None | 0 0
  1.  
  2. int load_mods()
  3. {
  4.     __android_log_write(ANDROID_LOG_INFO, "QuestHook", "Loading mods!");
  5.     if (setDataDirs() != 0)
  6.     {
  7.          __android_log_write(ANDROID_LOG_ERROR, "QuestHook", "Unable to determine data directories.");
  8.         return -1;
  9.     }
  10.     if (mkpath(modPath, 0) != 0)
  11.     {
  12.         __android_log_print(ANDROID_LOG_ERROR, "QuestHook", "Unable to access or create mod path at '%s'", modPath);
  13.         return -1;
  14.     }
  15.     if (mkpath(modTempPath, 0) != 0)
  16.     {
  17.         __android_log_print(ANDROID_LOG_ERROR, "QuestHook", "Unable to access or create mod temporary path at '%s'", modTempPath);
  18.         return -1;
  19.     }
  20.  
  21.     struct dirent *dp;
  22.     DIR *dir = opendir(modPath);
  23.  
  24.     while ((dp = readdir(dir)) != NULL)
  25.     {
  26.         if (strlen(dp->d_name) > 3 && !strcmp(dp->d_name + strlen(dp->d_name) - 3, ".so"))
  27.         {
  28.             char full_path[PATH_MAX];
  29.             strcpy(full_path, modPath);
  30.             strcat(full_path, dp->d_name);
  31.             __android_log_print(ANDROID_LOG_INFO, "QuestHook", "Loading mod: %s", full_path);
  32.             int infile = open(full_path, O_RDONLY);
  33.             off_t filesize = lseek(infile, 0, SEEK_END);
  34.             lseek(infile, 0, SEEK_SET);
  35.             unlink(modTempPath);
  36.             int outfile = open(modTempPath, O_CREAT | O_WRONLY);
  37.             sendfile(outfile, infile, 0, filesize);
  38.             close(infile);
  39.             close(outfile);
  40.             chmod(modTempPath, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP);
  41.             dlopen(modTempPath, RTLD_NOW);
  42.         }
  43.     }
  44.     closedir(dir);
  45.     return 0;
  46. }
  47.  
  48. __attribute__((constructor)) void lib_main()
  49. {
  50.     __android_log_write(ANDROID_LOG_INFO, "QuestHook", "Welcome!");
  51.     if (load_mods() != 0)
  52.     {
  53.         __android_log_write(ANDROID_LOG_ERROR, "QuestHook", "QuestHook failed to initialize, mods will not load.");
  54.         return;
  55.     }
  56.     else
  57.     {
  58.         __android_log_write(ANDROID_LOG_INFO, "QuestHook", "Done loading mods!");
  59.     }    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement