Advertisement
Baoulettes

test bgm 4f

May 12th, 2020
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.29 KB | None | 0 0
  1. #include <fmt/format.h>
  2. #include <dokkan/files.h>
  3. #include <dokkan/instances.h>
  4. #include <unidokkan/ui/defs.h>
  5. #include <unidokkan/ui/label.h>
  6. #include <unidokkan/ui/scene.h>
  7. #include <unidokkan/ui/button.h>
  8. #include <unidokkan/ui/layout.h>
  9. #include <unidokkan/ui/imageview.h>
  10. #include <unidokkan/ui/progresstimer.h>
  11. #include <cocos/ui/UIButton.h>
  12. #include <cocos/base/CCDirector.h>
  13. #include <cocos/2d/CCActionInterval.h>
  14. #include <unidokkan/errors.h>
  15. #include <string>
  16. using namespace UniDokkan::UI;
  17. namespace cocos2d = ud_cocos2d;
  18. auto PlayBGM    =   DokkanFunction<void *(void*, int, double, bool)>("_ZNK22OutGameSoundPlayerBase7playBgmEidb");
  19. auto SetMute    =   DokkanFunction<void *(void*, bool)>("_ZN5Sound3Bgm4muteEb");
  20. int counter     =   0;
  21. int in_line     =   0;
  22.  
  23. void (*ori__CharacterMenuScene_onEnter)(void *self)= nullptr;
  24. void CharacterMenuScene_onEnter(void *self) {
  25.     UD_LOGI("init");
  26.     ori__CharacterMenuScene_onEnter(self);
  27.     auto screen_size = cocos2d_Director_getVisibleSize(UniDokkan::Dokkan::cocos2d_Director_getInstance());
  28.     auto Music_player_1 = new Scene();
  29.     Music_player_1->retain();
  30.     //Scene music Player
  31.     auto background_image = new ImageView("background", Music_player_1);
  32.     background_image->loadImage("baou_jukebox/layout/image/common/com_bg_menu.png");
  33.     background_image->setAnchorPoint(Node::AnchorCenter);
  34.     auto insets = cocos2d::Rect(0, 0, 0, 0);
  35.     background_image->scale9(&insets);
  36.     background_image->setContentSize(screen_size);
  37.     background_image->setPosition({screen_size.width/2,screen_size.height/2});
  38.     auto layout = new Layout("Absolute_sized", Music_player_1, cocos2d::ui::Layout::Type::ABSOLUTE);
  39.     layout->setContentSize(screen_size - cocos2d::Size(100, 100));
  40.     layout->setPosition({0, 0});
  41.     //{line_h/2, 10.0f} bottom left + margin
  42.     std::string fntfile = "baou_jukebox/fonts/ja/custom/btn_normal/btn_normal.fnt";
  43.     auto file_utils =   UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
  44.     if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, fntfile)) {
  45.         fntfile = "baou_jukebox/fonts/ja/custom/btn_normal/btn_normal.fnt";
  46.         UD_LOGI("Using : %s", fntfile.c_str());
  47.     } else {
  48.         fntfile = "baou_jukebox/fonts/fonts/fr/custom/btn_normal/btn_normal.fnt";
  49.         UD_LOGI("Using : %s", fntfile.c_str());
  50.     }
  51.    
  52.     UD_LOGI("creating : BGMList");
  53.     auto Title = new Label("BGMList", layout,1000);
  54.     Title->setBMFont(fntfile, 15.0f, {0.0f,0.0f});
  55.     Title->setCaption("Liste des BGM");
  56.     Title->setFontSize(30.0f);
  57.     Title->setPosition({screen_size.width/2, screen_size.height - 50.0f});
  58.     Title->setAnchorPoint(Node::AnchorCenter);
  59.     UD_LOGI("creating : CurrPlaying");
  60.     auto CurrentlyPlaying = new Label("CurrPlaying", layout,1000);
  61.     CurrentlyPlaying->setBMFont(fntfile, 15.0f, {0.0f,0.0f});
  62.     CurrentlyPlaying->setCaption("En cours de lecture : Rien");
  63.     CurrentlyPlaying->setFontSize(16.0f);
  64.     CurrentlyPlaying->setPosition({screen_size.width/2, screen_size.height - 120.0f});
  65.     CurrentlyPlaying->setAnchorPoint(Node::AnchorCenter);  
  66.     UD_LOGI("setting");
  67.     float line_v    =   screen_size.height - 200.0f; // header
  68.     float line_h    =   screen_size.width/4;
  69.     line_h          =   line_h - 20.0f;
  70.     float add_h     =   160.0f; // guessing width of btn
  71.     auto firststpos =   background_image->getPosition();
  72.     float middlef   =   screen_size.width/2;
  73.     UD_LOGI("listing bgms");
  74.     for (int i = 1; i < 999; i++) {
  75.         auto path = fmt::format("bgm/bgm_{:#03d}.awb", i);
  76.         if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, path)) {
  77.             if (in_line == 7) {
  78.                 in_line = 0;
  79.                 counter = 0;
  80.                 line_v  =   line_v - 40.0f;
  81.                 line_h  =   screen_size.width/4;
  82.                 line_h  =   line_h - 25.0f;
  83.             }
  84.             if (counter == 0) {
  85.                 line_h  =   screen_size.width/4;
  86.             } else {
  87.                 line_h  =   line_h + add_h;
  88.             }
  89.             counter++;
  90.             in_line++;
  91.             int curr_id                 =   i;
  92.             std::string curr_id_str     =   std::to_string(i);
  93.             std::string curr_id_str_l   =   std::to_string(i)+"_label";
  94.             auto play_bgm = new Button(curr_id_str, layout,1000);
  95.             UD_LOGI("creating btn bgm");
  96.             play_bgm->setDefaultImage("baou_jukebox/layout/image/common/btn/com_btn_16_yellow.png");
  97.             //play_bgm->setCaption(curr_id_str);
  98.             auto IDLabel = new Label(curr_id_str_l, layout,1000);
  99.             auto YPosLab = line_v + 10.0f;
  100.             IDLabel->setBMFont(fntfile, 15.0f, {0.0f,-500.0f});
  101.             IDLabel->setPosition({line_h/2, YPosLab});
  102.             IDLabel->setCaption(curr_id_str);
  103.             IDLabel->setFontSize(14.0f);
  104.             UD_LOGI("position btn bgm");
  105.             play_bgm->setPosition({line_h/2, line_v});
  106.             play_bgm->setScale(1.0, 1.0);
  107.             play_bgm->setAnchorPoint(Node::AnchorCenter);
  108.             play_bgm->setFontColor(cocos2d::Color3B::BLACK);
  109.             play_bgm->addClickEventListener([=](Widget*) {
  110.                 CurrentlyPlaying->setCaption("En cours de lecture : " + curr_id_str);
  111.                 PlayBGM(self,curr_id,0,true);
  112.             });
  113.         } else {
  114.             //UD_LOGI("File Not Exist : %s", path.c_str());
  115.         }
  116.     }
  117.     UD_LOGI("Fermerbtn");
  118.     auto Fermer = new Label("Fermerbtn", layout,1000);
  119.     Fermer->setBMFont(fntfile, 15.0f, {0.0f,0.0f});
  120.     Fermer->setCaption("Fermer");
  121.     Fermer->setFontSize(18.0f);
  122.     Fermer->setPosition({middlef, 93.0f});
  123.     Fermer->setAnchorPoint(Node::AnchorCenter);
  124.     UD_LOGI("close_list");
  125.     auto close_list = new Button("close_list", layout);
  126.     close_list->setDefaultImage("baou_jukebox/layout/image/common/btn/com_btn_01_orange.png");
  127.     close_list->setPosition({middlef, 80.0f});
  128.     close_list->setAnchorPoint(Node::AnchorCenter);
  129.     close_list->setFontColor(cocos2d::Color3B::BLACK);
  130.     close_list->addClickEventListener([=](Widget*) {
  131.         //Scene::popCurrent();
  132.         in_line = 0;
  133.         counter = 0;
  134.         TransitionFade transition_fade(1.0f, cocos2d::Color3B::BLACK);
  135.         // ori__CharacterMenuScene_onEnter(self);
  136.         Music_player_1->popCurrent();
  137.     });
  138.     UD_LOGI("pathdb");
  139.     //Home Menu button
  140.     //Check if glb or japan :
  141.     auto pathdb =   "sqlite/current/database.db";
  142.     auto OriW   =   screen_size.width;
  143.     auto OriH   =   screen_size.height;
  144.     float Ypos  =   OriH/2;
  145.     float YposN =   Ypos;
  146.     float XPos  =   OriW/2;
  147.     if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, pathdb)) {
  148.         YposN = Ypos-292.0f;
  149.     } else {
  150.         YposN = Ypos-169.0f;
  151.     }
  152.     UD_LOGI("menu_icon_addon");
  153.     auto left_icon = new ImageView("menu_icon_addon", self, 200);
  154.     left_icon->loadImage("baou_jukebox/layout/image/common/btn/menu_icon_addon.png");
  155.     left_icon->setAnchorPoint(Node::AnchorCenter);;
  156.     left_icon->setPosition({XPos+54.0f, YposN+4.0f});
  157.     UD_LOGI("menu_title_addon");
  158.     auto btn_label = new ImageView("menu_title_addon", self, 200);
  159.     btn_label->loadImage("baou_jukebox/layout/image/common/btn/menu_title_addon.png");
  160.     btn_label->setAnchorPoint(Node::AnchorCenter);
  161.     btn_label->setPosition({XPos+194.0f, YposN});
  162.     UD_LOGI("open_playerbtn");
  163.     auto open_player = new Button("open_playerbtn", self, 100);
  164.     open_player->setDefaultImage("baou_jukebox/layout/image/common/btn/com_btn_menu_chara_gray.png");
  165.     open_player->setGravity(cocos2d::ui::LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
  166.     open_player->setPosition({XPos+162.0f, YposN});
  167.     open_player->addClickEventListener([=](Widget*) {
  168.         TransitionFade transition_fade(1.0f, cocos2d::Color3B::BLACK);
  169.         Music_player_1->push();
  170.     });
  171.     UD_LOGI("End of functions");
  172. }
  173. extern "C" {
  174.     __attribute__ ((visibility ("default")))
  175.     int unidokkan_init_v3(HookLibV3 *hook_lib) {
  176.         UD_LOGI("Jukebox custom module loading...");
  177.  
  178.         if (hook_lib->size < sizeof(HookLibV3)) {
  179.             return UD_MODULE_INVALID_SIZE;
  180.         }
  181.  
  182.         if (hook_lib->version < kMinPatcherVer) {
  183.             return UD_MODULE_INVALID_VERSION;
  184.         }
  185.         auto res = hook_lib->applyHooks({
  186.             // {DOKKAN_LIB, "_ZN24LayoutIngameIngameBattle4initEv", (bool*)CharacterMenuScene_onEnter},
  187.             {DOKKAN_LIB, "_ZN16InGameFooterView7onEnterEv", reinterpret_cast<void *>(CharacterMenuScene_onEnter), reinterpret_cast<void **>(&ori__CharacterMenuScene_onEnter)},
  188.             // {DOKKAN_LIB, "_ZThn8_N16InGameFooterView4initEv", <void*>(CharacterMenuScene_onEnter), <void**>(&ori__CharacterMenuScene_onEnter)},
  189.             // {DOKKAN_LIB, "_ZN18CharacterMenuScene7onEnterEv", reinterpret_cast<void *>(CharacterMenuScene_onEnter), reinterpret_cast<void **>(&ori__CharacterMenuScene_onEnter)},
  190.         });
  191.        
  192.         if (!res) {
  193.             return UD_MODULE_ERROR;
  194.         }
  195.  
  196.         UD_LOGI("Jukebox module successfully loaded.");
  197.         return UD_MODULE_SUCCESS;
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement