Advertisement
Baoulettes

is this a ghost wallpaper being made?

May 22nd, 2020
2,831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.09 KB | None | 0 0
  1. #include <dokkan/defs.h>
  2. #include <dokkan/files.h>
  3. #include <unidokkan/hook.h>
  4. #include <unidokkan/errors.h>
  5. #include <dokkan/instances.h>
  6. #include <unidokkan/database.h>
  7. #include <unidokkan/ui/scene.h>
  8. #include <unidokkan/ui/layout.h>
  9. #include <unidokkan/ui/button.h>
  10. #include <unidokkan/ui/imageview.h>
  11. using json = nlohmann::json;
  12. using namespace UniDokkan::UI;
  13. namespace cocos2d = ud_cocos2d;
  14. int Wallpaper_id;
  15. // _ZN13HomeMenuScene12setWallpaperERKNSt6__ndk110shared_ptrI13WallpaperItemEE
  16. // Forward reference, ignore
  17. void DatabaseReadyCallback() {
  18.     UD_LOGV("Add customs wallpaper in database init");
  19.     std::string AddWallpapers = "PRAGMA synchronous = OFF;";
  20.     AddWallpapers.append("PRAGMA journal_mode = OFF;");
  21.     AddWallpapers.append("BEGIN EXCLUSIVE TRANSACTION;");
  22.     AddWallpapers.append("PRAGMA defer_foreign_keys = ON;");
  23.     for (int i1 = 1000; i1 == 1100;) {
  24.         auto file_utils =   UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
  25.         auto path = "item/wallpaper/" + std::to_string(i1) + "/" + std::to_string(i1) + ".lwf";
  26.         if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path)) {
  27.             UD_LOGV("Found a wallpaper with id : %d",i1);
  28.             AddWallpapers.append("INSERT INTO \"wallpaper_items\" (\"id\", \"name\", \"description\", \"created_at\", \"updated_at\") VALUES ('" + std::to_string(i1) + "', 'Custom Wallpaper " + std::to_string(i1) + "', 'Custom wallpaper. \nRequire this patch to work !', '2020-02-20 02:10:19', '2020-02-20 02:10:19');");
  29.             continue;
  30.         } else {
  31.             UD_LOGV("Not Found a wallpaper with id : %d",i1);
  32.             continue;
  33.         }
  34.     }
  35.     AddWallpapers.append("COMMIT TRANSACTION;");
  36.     AddWallpapers.append("PRAGMA optimize;");
  37.     AddWallpapers.append("PRAGMA synchronous = NORMAL;");
  38.     AddWallpapers.append("PRAGMA journal_mode = DELETE;");
  39.     AddWallpapers.append("PRAGMA shrink_memory;");
  40.     UniDokkan::Database::exec(AddWallpapers);
  41. }
  42. void (*ori_WallpaperSelect)(void *) = nullptr;
  43. void WallpaperSelect(void *scene, HookLibV3* hook_lib) {
  44.     UD_LOGV("Init Wallpaper list");
  45.     ori_WallpaperSelect(scene);
  46.     auto screen_size = cocos2d_Director_getVisibleSize(UniDokkan::Dokkan::cocos2d_Director_getInstance()); 
  47.     cocos2d::Vec2 setup_position = screen_size / 2;
  48.     auto    Init_H          =   screen_size.height / 2;
  49.     auto    Init_W          =   screen_size.width / 2;
  50.     auto    line_v          =   screen_size.height / 2;
  51.             line_v          =   line_v - 0.0f;
  52.     auto    line_h          =   screen_size.width / 4;
  53.     int     cpw             =   0;  //current page W
  54.     static float initw      =   line_h;
  55.     static float inith      =   line_v;
  56.     int     lines_c         =   1;
  57.     int     curr_p          =   1;
  58.     float   btn_h           =   300.0f;
  59.     float   btn_w           =   300.0f;
  60.     float   slide           =   0.2f;
  61.     int     btnpp           =   6;          //btn per line)
  62.     float   p_w1            =   btn_w * btnpp; //page width
  63.     float   pmarg           =   1000.0f;
  64.     float   p_w             =   p_w1 + pmarg;
  65.     int     slide_se        =   4;
  66.     int     click_se        =   2;
  67.     int     counter         =   0;
  68.     int     in_line         =   0;
  69.     int     maxline         =   10;
  70.     //_ZN28LayoutMenuMenuWallpaperThumb6createEv
  71.     auto Wallpapers_list = new Layout("Wallpapers_list_a_s", scene, cocos2d::ui::Layout::Type::ABSOLUTE,10000);
  72.     Wallpapers_list->setPosition({0, 0});
  73.     Wallpapers_list->setContentSize(screen_size - cocos2d::Size{100, 100});
  74.     auto background = new ImageView("background", Wallpapers_list, -1);
  75.     background->loadImage("baou_zelda_jukebox/layout/image/common/bgm_list_ig.png");
  76.     background->setAnchorPoint(cocos2d::Vec2::ANCHOR_MIDDLE);
  77.     background->setSwallowTouches(true);
  78.     background->setPosition(setup_position);
  79.     background->setContentSize(screen_size - cocos2d::Size{100, 100});
  80.    
  81.     for (int i = 999; i < 1101; i++) {
  82.         UD_LOGV("Current ID :%d",i);
  83.         auto file_utils =   UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
  84.         auto path = "item/wallpaper/" + std::to_string(i) + "/" + std::to_string(i) + ".lwf";
  85.         if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path)) {
  86.             UD_LOGV("Found a wallpaper with id : %d",i);
  87.             auto path2 = "item/wallpaper/" + std::to_string(i) + "/thumb_" + std::to_string(i) + ".png";
  88.             if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path2)) {
  89.                 auto path3 = "item/wallpaper/" + std::to_string(i) + "/icon_" + std::to_string(i) + ".png";
  90.                 if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path3)) {
  91.                     std::string layout_image_base_path  =   "baou_jukebox/layout/image/common/btn/";
  92.                     std::string font_file_path          =   "baou_jukebox/fonts/ja/custom/btn_normal/btn_normal.fnt";
  93.                     if (in_line == btnpp && lines_c == maxline){
  94.                         UD_LOGV("in_line == btnpp && lines_c == maxline");
  95.                         in_line =   0;
  96.                         lines_c =   1;
  97.                         cpw++;
  98.                         line_h  =   initw + (p_w * cpw);
  99.                         line_v  =   inith;
  100.                     }
  101.                     if (in_line == btnpp){
  102.                         UD_LOGV("in_line == btnpp");
  103.                         line_h  =   initw + (p_w * cpw);
  104.                         line_v  =   line_v - btn_h;
  105.                         in_line =   0;
  106.                         lines_c++;
  107.                     }
  108.  
  109.                     int curr_id                 =   i;
  110.                     std::string curr_id_str     =   std::to_string(i);
  111.                     std::string curr_id_str_l   =   fmt::format("{}_label", i);
  112.  
  113.                     auto Wallpaper_btn = new Button(curr_id_str, Wallpapers_list, 2);
  114.                     Wallpaper_btn->setDefaultImage(path3);
  115.  
  116.                     auto bgm_track_label = new Label(curr_id_str_l, Wallpapers_list, 3);
  117.                     auto YPosLab = line_v + 10.0f;
  118.                     bgm_track_label->setBMFont(font_file_path, 14.0f);
  119.                     bgm_track_label->setPosition({line_h / 2, YPosLab});
  120.                     bgm_track_label->setCaption(curr_id_str);
  121.  
  122.                     Wallpaper_btn->setPosition({line_h/2, line_v});
  123.                     Wallpaper_btn->setScale(0.6f, 0.6f);
  124.                     Wallpaper_btn->setAnchorPoint(cocos2d::Vec2::ANCHOR_MIDDLE);
  125.                     Wallpaper_btn->setFontColor(cocos2d::Color3B::BLACK);
  126.                     Wallpaper_btn->addClickEventListener([=](Widget*) {
  127.                         // HookLibV3 *kHookLib;
  128.                         // hook_lib->patchData.registerPatch();
  129.                         Wallpaper_id    =    hook_lib->patchData.getInt32("c_wallpaper_id", 1);
  130.                         UD_LOGV("Older Wallpaper ID:%d",Wallpaper_id);
  131.                         UD_LOGV("New Wallpaper ID:%d",i);
  132.                         hook_lib->patchData.putInt32("c_wallpaper_id", i);
  133.                        
  134.                         UD_LOGV("New Wallpaper has been saved.");
  135.                     });
  136.                     counter++;
  137.                     in_line++;
  138.                 } else {
  139.                     UD_LOGV("Wallpaper ID:%d : icon_%d.png not found !",i,i);
  140.                 }
  141.             } else {
  142.                 UD_LOGV("Wallpaper ID:%d : thumb_%d.png not found !",i,i);
  143.             }
  144.         }
  145.     }
  146. }
  147. void *(*ori__ori_wp_list)(void *, bool) = nullptr; //
  148. void *ori_wp_list(void *self, bool create_new) {
  149.     auto label = ori__ori_wp_list(self, create_new);
  150.     auto setPositionX   =   DokkanFunction<void *(void *, float)>("_ZN7cocos2d4Node12setPositionXEf");
  151.     if (!create_new) { return label;  }
  152.     setPositionX(label, 9999.0f);
  153.     return label;
  154. }
  155. bool ModifyWallpaper(NetworkResponse *response) {
  156.     UD_LOGI("ModifyWallpaper modify our original wallpaper to custom one : %d", Wallpaper_id);
  157.     response->jsonBody["user"]["wallpaper_item_id"] = Wallpaper_id;
  158.     return true;
  159. }
  160. void wallpaper_adder(HookLibV3* hook_lib);
  161. extern "C" {
  162.     __attribute__ ((visibility ("default")))
  163.     int unidokkan_init_v3(HookLibV3* hook_lib) {
  164.         UD_LOGI("wallpaper_adder custom module loading...");
  165.         if (hook_lib->size < sizeof(HookLibV3)) { return UD_MODULE_INVALID_SIZE;}
  166.         if (hook_lib->version < kMinPatcherVer) { return UD_MODULE_INVALID_VERSION;}
  167.  
  168.         /* You can only call disableInGameSaving() from unidokkan_init_v3()
  169.          *
  170.          * Once this is called, in game saving is disabled permanently and
  171.          * cannot be re-enabled.
  172.          */
  173.         // hook_lib->disableInGameSaving();
  174.         /*
  175.          * To use the patch data functionality, you must first register
  176.          * your patch. If this is the first time your patch is running,
  177.          * it will generate encryption keys and a separate database table
  178.          * that your patch will be able to store and read data from.
  179.          *
  180.          * If you do not call register patch before reading or writing
  181.          * patch data, you will run into issues.
  182.          */
  183.         hook_lib->patchData.registerPatch();
  184.         /*
  185.          * For the patch data demonstration, let's save the date/time of
  186.          * the first launch of our patch. We will save it under "first_launch".
  187.          *
  188.          * First, we'll check to see if that data exists.
  189.          */
  190.         if (!hook_lib->patchData.exists("c_wallpaper_id")) {
  191.             /*
  192.              * The "first_launch" key doesn't exist.
  193.              *
  194.              * Let's set it to the current date and time.
  195.              */
  196.             UD_LOGI("wallpaper_adder since no custom wallpaper as bin set let add a random one");
  197.             hook_lib->patchData.putInt32("c_wallpaper_id", 1);
  198.         }
  199.         /*
  200.          * Now we get the data of "first_launch" and print it to the log.
  201.          */
  202.         UD_LOGI("wallpaper_adder now it should read 1000 or something else 0!");
  203.         UD_LOGI("Wallpaper id is %d", hook_lib->patchData.getInt32("c_wallpaper_id",1));
  204.         Wallpaper_id    =    hook_lib->patchData.getInt32("c_wallpaper_id", 1);
  205.         /*
  206.          * This function tests the different methods of saving data.
  207.          * You can see it's implementation below.
  208.          */
  209.         wallpaper_adder(hook_lib);
  210.         // UniDokkan::Database::addDatabaseReadyCallback(DatabaseReadyCallback);
  211.         hook_lib->addResponseHook("(^/user$|^.*user=.*$)", ModifyWallpaper);
  212.        
  213.         auto res = hook_lib->applyHooks({
  214.             {DOKKAN_LIB, "_ZN23LayoutMenuMenuWallpaper12getTableListEb", (void*)ori_wp_list, (void**)& ori__ori_wp_list},
  215.             {DOKKAN_LIB, "_ZN20WallpaperSelectScene12initListViewEv", reinterpret_cast<void *>(WallpaperSelect), reinterpret_cast<void **>(&ori_WallpaperSelect)},
  216.         });
  217.         if (!res) {
  218.             return UD_MODULE_ERROR;
  219.         }
  220.        
  221.         UD_LOGI("wallpaper_adder custom module successfully loaded.");
  222.         return UD_MODULE_SUCCESS;
  223.     }
  224. }
  225.  
  226. /*
  227.  * The following function tests to make sure all the different
  228.  * methods of saving data work.
  229.  *
  230.  * This is also a good show of what methods are available.
  231.  */
  232. void wallpaper_adder(HookLibV3* hook_lib) {
  233. #define DATA_TEST_STR "test string"
  234. #define DATA_TEST_INT32 -9'001u
  235. #define DATA_TEST_UINT32 9'001
  236. #define DATA_TEST_INT64 -8'589'934'592
  237. #define DATA_TEST_UINT64 8'589'934'592u
  238. #define DATA_TEST_FLOAT 9.001f
  239. #define DATA_TEST_DOUBLE 8'589'934'592.9001f
  240.     hook_lib->patchData.putString("test_string", DATA_TEST_STR);
  241.     assert(hook_lib->patchData.getString("test_string", "") == DATA_TEST_STR);
  242.     hook_lib->patchData.putInt32("test_int32", DATA_TEST_INT32);
  243.     assert(hook_lib->patchData.getInt32("test_int32", 0) == DATA_TEST_INT32);
  244.     hook_lib->patchData.putUInt32("test_uint32", DATA_TEST_UINT32);
  245.     assert(hook_lib->patchData.getUInt32("test_uint32", 0) == DATA_TEST_UINT32);
  246.     hook_lib->patchData.putInt64("test_int64", DATA_TEST_INT64);
  247.     assert(hook_lib->patchData.getInt64("test_int64", 0) == DATA_TEST_INT64);
  248.     hook_lib->patchData.putUInt64("test_uint64", DATA_TEST_UINT64);
  249.     assert(hook_lib->patchData.getUInt64("test_uint64", 0) == DATA_TEST_UINT64);
  250.     hook_lib->patchData.putFloat("test_float", DATA_TEST_FLOAT);
  251.     assert(hook_lib->patchData.getFloat("test_float", 0.0f) == DATA_TEST_FLOAT);
  252.     hook_lib->patchData.putDouble("test_double", DATA_TEST_DOUBLE);
  253.     assert(hook_lib->patchData.getDouble("test_double", 0.0f) == DATA_TEST_DOUBLE);
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement