Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dokkan/defs.h>
- #include <dokkan/files.h>
- #include <unidokkan/hook.h>
- #include <unidokkan/errors.h>
- #include <dokkan/instances.h>
- #include <unidokkan/database.h>
- #include <unidokkan/ui/scene.h>
- #include <unidokkan/ui/layout.h>
- #include <unidokkan/ui/button.h>
- #include <unidokkan/ui/imageview.h>
- using json = nlohmann::json;
- using namespace UniDokkan::UI;
- namespace cocos2d = ud_cocos2d;
- int Wallpaper_id;
- // _ZN13HomeMenuScene12setWallpaperERKNSt6__ndk110shared_ptrI13WallpaperItemEE
- // Forward reference, ignore
- void DatabaseReadyCallback() {
- UD_LOGV("Add customs wallpaper in database init");
- std::string AddWallpapers = "PRAGMA synchronous = OFF;";
- AddWallpapers.append("PRAGMA journal_mode = OFF;");
- AddWallpapers.append("BEGIN EXCLUSIVE TRANSACTION;");
- AddWallpapers.append("PRAGMA defer_foreign_keys = ON;");
- for (int i1 = 1000; i1 == 1100;) {
- auto file_utils = UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
- auto path = "item/wallpaper/" + std::to_string(i1) + "/" + std::to_string(i1) + ".lwf";
- if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path)) {
- UD_LOGV("Found a wallpaper with id : %d",i1);
- 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');");
- continue;
- } else {
- UD_LOGV("Not Found a wallpaper with id : %d",i1);
- continue;
- }
- }
- AddWallpapers.append("COMMIT TRANSACTION;");
- AddWallpapers.append("PRAGMA optimize;");
- AddWallpapers.append("PRAGMA synchronous = NORMAL;");
- AddWallpapers.append("PRAGMA journal_mode = DELETE;");
- AddWallpapers.append("PRAGMA shrink_memory;");
- UniDokkan::Database::exec(AddWallpapers);
- }
- void (*ori_WallpaperSelect)(void *) = nullptr;
- void WallpaperSelect(void *scene, HookLibV3* hook_lib) {
- UD_LOGV("Init Wallpaper list");
- ori_WallpaperSelect(scene);
- auto screen_size = cocos2d_Director_getVisibleSize(UniDokkan::Dokkan::cocos2d_Director_getInstance());
- cocos2d::Vec2 setup_position = screen_size / 2;
- auto Init_H = screen_size.height / 2;
- auto Init_W = screen_size.width / 2;
- auto line_v = screen_size.height / 2;
- line_v = line_v - 0.0f;
- auto line_h = screen_size.width / 4;
- int cpw = 0; //current page W
- static float initw = line_h;
- static float inith = line_v;
- int lines_c = 1;
- int curr_p = 1;
- float btn_h = 300.0f;
- float btn_w = 300.0f;
- float slide = 0.2f;
- int btnpp = 6; //btn per line)
- float p_w1 = btn_w * btnpp; //page width
- float pmarg = 1000.0f;
- float p_w = p_w1 + pmarg;
- int slide_se = 4;
- int click_se = 2;
- int counter = 0;
- int in_line = 0;
- int maxline = 10;
- //_ZN28LayoutMenuMenuWallpaperThumb6createEv
- auto Wallpapers_list = new Layout("Wallpapers_list_a_s", scene, cocos2d::ui::Layout::Type::ABSOLUTE,10000);
- Wallpapers_list->setPosition({0, 0});
- Wallpapers_list->setContentSize(screen_size - cocos2d::Size{100, 100});
- auto background = new ImageView("background", Wallpapers_list, -1);
- background->loadImage("baou_zelda_jukebox/layout/image/common/bgm_list_ig.png");
- background->setAnchorPoint(cocos2d::Vec2::ANCHOR_MIDDLE);
- background->setSwallowTouches(true);
- background->setPosition(setup_position);
- background->setContentSize(screen_size - cocos2d::Size{100, 100});
- for (int i = 999; i < 1101; i++) {
- UD_LOGV("Current ID :%d",i);
- auto file_utils = UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
- auto path = "item/wallpaper/" + std::to_string(i) + "/" + std::to_string(i) + ".lwf";
- if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path)) {
- UD_LOGV("Found a wallpaper with id : %d",i);
- auto path2 = "item/wallpaper/" + std::to_string(i) + "/thumb_" + std::to_string(i) + ".png";
- if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path2)) {
- auto path3 = "item/wallpaper/" + std::to_string(i) + "/icon_" + std::to_string(i) + ".png";
- if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path3)) {
- std::string layout_image_base_path = "baou_jukebox/layout/image/common/btn/";
- std::string font_file_path = "baou_jukebox/fonts/ja/custom/btn_normal/btn_normal.fnt";
- if (in_line == btnpp && lines_c == maxline){
- UD_LOGV("in_line == btnpp && lines_c == maxline");
- in_line = 0;
- lines_c = 1;
- cpw++;
- line_h = initw + (p_w * cpw);
- line_v = inith;
- }
- if (in_line == btnpp){
- UD_LOGV("in_line == btnpp");
- line_h = initw + (p_w * cpw);
- line_v = line_v - btn_h;
- in_line = 0;
- lines_c++;
- }
- int curr_id = i;
- std::string curr_id_str = std::to_string(i);
- std::string curr_id_str_l = fmt::format("{}_label", i);
- auto Wallpaper_btn = new Button(curr_id_str, Wallpapers_list, 2);
- Wallpaper_btn->setDefaultImage(path3);
- auto bgm_track_label = new Label(curr_id_str_l, Wallpapers_list, 3);
- auto YPosLab = line_v + 10.0f;
- bgm_track_label->setBMFont(font_file_path, 14.0f);
- bgm_track_label->setPosition({line_h / 2, YPosLab});
- bgm_track_label->setCaption(curr_id_str);
- Wallpaper_btn->setPosition({line_h/2, line_v});
- Wallpaper_btn->setScale(0.6f, 0.6f);
- Wallpaper_btn->setAnchorPoint(cocos2d::Vec2::ANCHOR_MIDDLE);
- Wallpaper_btn->setFontColor(cocos2d::Color3B::BLACK);
- Wallpaper_btn->addClickEventListener([=](Widget*) {
- // HookLibV3 *kHookLib;
- // hook_lib->patchData.registerPatch();
- Wallpaper_id = hook_lib->patchData.getInt32("c_wallpaper_id", 1);
- UD_LOGV("Older Wallpaper ID:%d",Wallpaper_id);
- UD_LOGV("New Wallpaper ID:%d",i);
- hook_lib->patchData.putInt32("c_wallpaper_id", i);
- UD_LOGV("New Wallpaper has been saved.");
- });
- counter++;
- in_line++;
- } else {
- UD_LOGV("Wallpaper ID:%d : icon_%d.png not found !",i,i);
- }
- } else {
- UD_LOGV("Wallpaper ID:%d : thumb_%d.png not found !",i,i);
- }
- }
- }
- }
- void *(*ori__ori_wp_list)(void *, bool) = nullptr; //
- void *ori_wp_list(void *self, bool create_new) {
- auto label = ori__ori_wp_list(self, create_new);
- auto setPositionX = DokkanFunction<void *(void *, float)>("_ZN7cocos2d4Node12setPositionXEf");
- if (!create_new) { return label; }
- setPositionX(label, 9999.0f);
- return label;
- }
- bool ModifyWallpaper(NetworkResponse *response) {
- UD_LOGI("ModifyWallpaper modify our original wallpaper to custom one : %d", Wallpaper_id);
- response->jsonBody["user"]["wallpaper_item_id"] = Wallpaper_id;
- return true;
- }
- void wallpaper_adder(HookLibV3* hook_lib);
- extern "C" {
- __attribute__ ((visibility ("default")))
- int unidokkan_init_v3(HookLibV3* hook_lib) {
- UD_LOGI("wallpaper_adder custom module loading...");
- if (hook_lib->size < sizeof(HookLibV3)) { return UD_MODULE_INVALID_SIZE;}
- if (hook_lib->version < kMinPatcherVer) { return UD_MODULE_INVALID_VERSION;}
- /* You can only call disableInGameSaving() from unidokkan_init_v3()
- *
- * Once this is called, in game saving is disabled permanently and
- * cannot be re-enabled.
- */
- // hook_lib->disableInGameSaving();
- /*
- * To use the patch data functionality, you must first register
- * your patch. If this is the first time your patch is running,
- * it will generate encryption keys and a separate database table
- * that your patch will be able to store and read data from.
- *
- * If you do not call register patch before reading or writing
- * patch data, you will run into issues.
- */
- hook_lib->patchData.registerPatch();
- /*
- * For the patch data demonstration, let's save the date/time of
- * the first launch of our patch. We will save it under "first_launch".
- *
- * First, we'll check to see if that data exists.
- */
- if (!hook_lib->patchData.exists("c_wallpaper_id")) {
- /*
- * The "first_launch" key doesn't exist.
- *
- * Let's set it to the current date and time.
- */
- UD_LOGI("wallpaper_adder since no custom wallpaper as bin set let add a random one");
- hook_lib->patchData.putInt32("c_wallpaper_id", 1);
- }
- /*
- * Now we get the data of "first_launch" and print it to the log.
- */
- UD_LOGI("wallpaper_adder now it should read 1000 or something else 0!");
- UD_LOGI("Wallpaper id is %d", hook_lib->patchData.getInt32("c_wallpaper_id",1));
- Wallpaper_id = hook_lib->patchData.getInt32("c_wallpaper_id", 1);
- /*
- * This function tests the different methods of saving data.
- * You can see it's implementation below.
- */
- wallpaper_adder(hook_lib);
- // UniDokkan::Database::addDatabaseReadyCallback(DatabaseReadyCallback);
- hook_lib->addResponseHook("(^/user$|^.*user=.*$)", ModifyWallpaper);
- auto res = hook_lib->applyHooks({
- {DOKKAN_LIB, "_ZN23LayoutMenuMenuWallpaper12getTableListEb", (void*)ori_wp_list, (void**)& ori__ori_wp_list},
- {DOKKAN_LIB, "_ZN20WallpaperSelectScene12initListViewEv", reinterpret_cast<void *>(WallpaperSelect), reinterpret_cast<void **>(&ori_WallpaperSelect)},
- });
- if (!res) {
- return UD_MODULE_ERROR;
- }
- UD_LOGI("wallpaper_adder custom module successfully loaded.");
- return UD_MODULE_SUCCESS;
- }
- }
- /*
- * The following function tests to make sure all the different
- * methods of saving data work.
- *
- * This is also a good show of what methods are available.
- */
- void wallpaper_adder(HookLibV3* hook_lib) {
- #define DATA_TEST_STR "test string"
- #define DATA_TEST_INT32 -9'001u
- #define DATA_TEST_UINT32 9'001
- #define DATA_TEST_INT64 -8'589'934'592
- #define DATA_TEST_UINT64 8'589'934'592u
- #define DATA_TEST_FLOAT 9.001f
- #define DATA_TEST_DOUBLE 8'589'934'592.9001f
- hook_lib->patchData.putString("test_string", DATA_TEST_STR);
- assert(hook_lib->patchData.getString("test_string", "") == DATA_TEST_STR);
- hook_lib->patchData.putInt32("test_int32", DATA_TEST_INT32);
- assert(hook_lib->patchData.getInt32("test_int32", 0) == DATA_TEST_INT32);
- hook_lib->patchData.putUInt32("test_uint32", DATA_TEST_UINT32);
- assert(hook_lib->patchData.getUInt32("test_uint32", 0) == DATA_TEST_UINT32);
- hook_lib->patchData.putInt64("test_int64", DATA_TEST_INT64);
- assert(hook_lib->patchData.getInt64("test_int64", 0) == DATA_TEST_INT64);
- hook_lib->patchData.putUInt64("test_uint64", DATA_TEST_UINT64);
- assert(hook_lib->patchData.getUInt64("test_uint64", 0) == DATA_TEST_UINT64);
- hook_lib->patchData.putFloat("test_float", DATA_TEST_FLOAT);
- assert(hook_lib->patchData.getFloat("test_float", 0.0f) == DATA_TEST_FLOAT);
- hook_lib->patchData.putDouble("test_double", DATA_TEST_DOUBLE);
- assert(hook_lib->patchData.getDouble("test_double", 0.0f) == DATA_TEST_DOUBLE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement