Advertisement
Baoulettes

Animated categories filter label

Sep 6th, 2020
2,327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.69 KB | None | 0 0
  1. #include <dokkan/defs.h>
  2. #include <dokkan/files.h>
  3. #include <dokkan/cards.h>
  4. #include <unidokkan/log.h>
  5. #include <unidokkan/hook.h>
  6. #include <unidokkan/errors.h>
  7. #include <dokkan/instances.h>
  8. #include "cocos/base/CCData.h"
  9. #include <cocos/ui/UIWidget.h>
  10. #include <cocos/ui/UIButton.h>
  11. #include <cocos/ui/UILayout.h>
  12. #include <unidokkan/ui/button.h>
  13. #include <restclient-cpp/restclient.h>
  14. using namespace UniDokkan::UI;
  15. using json = nlohmann::json;
  16. namespace cocos2d       =   ud_cocos2d;
  17. int Clicked_Category    =   -1;
  18. int Clicked_Status      =   0;
  19. int Generated           =   0;
  20. std::vector<int> Categories_List;
  21. auto setFlash                           =   DokkanFunction<void(void *flash_view, const std::string lwf_path, const std::string scene_name)>("_ZN7cocos2d2ui9FlashView8setFlashERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEESA_");
  22. auto setPositionX                       =   DokkanFunction<void *(void *, float)>("_ZN7cocos2d4Node12setPositionXEf");
  23. auto setPositionY                       =   DokkanFunction<void *(void *, float)>("_ZN7cocos2d4Node12setPositionYEf");
  24. auto setVisible                         =   DokkanFunction<void(void *, bool)>("_ZN7cocos2d4Node10setVisibleEb");
  25. auto setZOrder                          =   DokkanFunction<void(void *, int)>("_ZN7cocos2d4Node9setZOrderEi");
  26. auto getZOrderEv                        =   DokkanFunction<int (void *)>("_ZNK7cocos2d4Node9getZOrderEv");
  27. auto getChildByName                     =   DokkanFunction<void *(void *, std::string)>("_ZNK7cocos2d4Node14getChildByNameERKNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE");
  28. static auto FileUtilsCustom_CpkLoader   =   DokkanFunction<ud_cocos2d::Data (const std::string &filename, bool text_file)>("_Z25FileUtilsCustom_CpkLoaderRKNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEb");
  29. std::string ReadTextFile(const std::string &filepath) {
  30.     auto data = FileUtilsCustom_CpkLoader(filepath, true);
  31.     ssize_t data_size;
  32.     auto buf = data.takeBuffer(&data_size);
  33.     return {buf, buf+data_size};
  34. }
  35. void *(*ori_DialogCardCategorySelector)(void *, const std::shared_ptr<UniDokkan::Dokkan::CardCategory> &, bool) = nullptr;
  36. void *DialogCardCategorySelector(void *self, const std::shared_ptr<UniDokkan::Dokkan::CardCategory> &category, bool selected) {
  37.     Clicked_Category            =   category->id; //Global Variable of category ID
  38.     auto DialogCardCatSel       =   ori_DialogCardCategorySelector(self, category, selected);
  39.     int b2i                     =   0;
  40.     int category_id             =   category->id;
  41.     std::string category_name   =   category->name;
  42.     if (!selected){ b2i = 0; } else { b2i = 1; }
  43.     Clicked_Status      =   b2i;
  44.     auto file_utils                 =   UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
  45.     std::string Json_path           =   "outgame/effect/animated_categories/ID.json";
  46.     auto json_data = nlohmann::json::parse(ReadTextFile(Json_path));
  47.     if (json_data["Categories_supported"].is_null() == false && Generated == 0){
  48.         for (auto& it : json_data["Categories_supported"]){
  49.             Categories_List.push_back(it.get<int>());
  50.         }
  51.         Generated = 1;
  52.     }
  53.     return DialogCardCatSel;
  54. }
  55. ud_cocos2d::ui::Button *(*ori__LayoutCharactermenuChaCategoryChaCategoryLabelSort_getFlaButton)(ud_cocos2d::ui::Widget *self, bool created) = nullptr;
  56. ud_cocos2d::ui::Button *LayoutCharactermenuChaCategoryChaCategoryLabelSort_getFlaButton(ud_cocos2d::ui::Widget *self, bool created) {
  57.     auto flash_button               =   ori__LayoutCharactermenuChaCategoryChaCategoryLabelSort_getFlaButton(self, created);
  58.     auto setFlash                   =   DokkanFunction<void(void *flash_view, const std::string lwf_path, const std::string scene_name)>("_ZN7cocos2d2ui9FlashView8setFlashERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEESA_");
  59.     auto getFlaEb                   =   DokkanFunction<void *(void *, bool)>("_ZN21LayoutMypageMypBanner10getFlaLoadEb");
  60.     if (Clicked_Category >= 1) {
  61.         auto HasAChild  =   getChildByName(self,"fla_load");
  62.         if (HasAChild == nullptr) {
  63.                 std::string LWF_Path        = "outgame/effect/animated_categories/cat_00000.lwf";
  64.                 std::string scene_name      = "cat_" + std::to_string(Clicked_Category);
  65.                 auto FlashStnBgEb           =   getFlaEb(self, true);
  66.                 setPositionX(FlashStnBgEb, 148.0f);
  67.                 setPositionY(FlashStnBgEb, 42.0f);
  68.                 setFlash(FlashStnBgEb,LWF_Path,scene_name);
  69.                 setZOrder(FlashStnBgEb,1);
  70.                 if (std::find(Categories_List.begin(), Categories_List.end(), Clicked_Category) != Categories_List.end()) {
  71.                     setZOrder(FlashStnBgEb,1);
  72.                 }
  73.         } else {
  74.             UD_LOGI("child found - L:64");
  75.             int Curr_Zorder             = getZOrderEv(HasAChild);
  76.             if (Curr_Zorder == 1) {
  77.                 setZOrder(HasAChild,-1);
  78.             } else if (Curr_Zorder == -1) {
  79.                 if (std::find(Categories_List.begin(), Categories_List.end(), Clicked_Category) != Categories_List.end()) {
  80.                     setZOrder(HasAChild,1);
  81.                 }
  82.             }
  83.         }
  84.     }
  85.     Clicked_Category = -1;
  86.     return flash_button;
  87. }
  88. extern "C" {
  89.     [[maybe_unused]] __attribute__ ((visibility ("default")))
  90.     int unidokkan_init_v4(HookLibV4* hook_lib) {
  91.         UD_LOGI("Animated categories filter label loading...");
  92.  
  93.         if (hook_lib->size < sizeof(HookLibV4)) { return UD_MODULE_INVALID_SIZE; }
  94.  
  95.         if (hook_lib->version < kMinPatcherVer) { return UD_MODULE_INVALID_VERSION; }
  96.  
  97.         auto res = hook_lib->applyHooks({
  98.             {DOKKAN_LIB, "_ZN12FilterDialog26DialogCardCategorySelectorINSt6__ndk110shared_ptrI14UserCardFilterEEE21refreshCategoryButtonERKNS2_I12CardCategoryEEb", DialogCardCategorySelector, &ori_DialogCardCategorySelector},
  99.             {DOKKAN_LIB, "_ZN50LayoutCharactermenuChaCategoryChaCategoryLabelSort12getFlaButtonEb", LayoutCharactermenuChaCategoryChaCategoryLabelSort_getFlaButton, &ori__LayoutCharactermenuChaCategoryChaCategoryLabelSort_getFlaButton},
  100.         });
  101.  
  102.         if (!res) { return UD_MODULE_ERROR; }
  103.  
  104.         UD_LOGI("Animated categories filter label successfully loaded.");
  105.         return UD_MODULE_SUCCESS;
  106.     }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement