Baoulettes

dokkan_turn_counter

May 17th, 2020
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.82 KB | None | 0 0
  1. #include <fmt/format.h>
  2. #include <unidokkan/errors.h>
  3. #include <unidokkan/hook.h>
  4. #include <dokkan/files.h>
  5. #include <dokkan/instances.h>
  6. #include <unidokkan/ui/defs.h>
  7. #include <unidokkan/ui/label.h>
  8. #include <unidokkan/ui/scene.h>
  9. #include <unidokkan/ui/button.h>
  10. #include <unidokkan/ui/layout.h>
  11. #include <unidokkan/ui/imageview.h>
  12. #include <unidokkan/ui/progresstimer.h>
  13. #include <cocos/ui/UIButton.h>
  14. #include <cocos/base/CCDirector.h>
  15. #include <cocos/2d/CCActionInterval.h>
  16. #include <unidokkan/database.h>
  17. #include <string>
  18. using namespace UniDokkan::UI;
  19. namespace cocos2d = ud_cocos2d;
  20. std::string BasePath;
  21. std::string Label_Turn;
  22. std::string Font_text   =   "btn_normal";
  23. std::string Font_number =   "gold_text";
  24. float Text_Size         =   10.0f;
  25. float Pos_X_Text        =   0.0f;
  26. float Pos_Y_Text        =   0.0f;
  27. float Pos_X_Number      =   0.0f;
  28. float Pos_Y_Number      =   0.0f;
  29. std::string label_ja    =   "sqlite/current/database.db";
  30. std::string label_fr    =   "french.txt";
  31. std::string label_en    =   "english.txt";
  32. std::string DetectLanguage(){
  33.     UD_LOGI("Language detection : init");
  34.     auto file_utils         =   UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
  35.     auto xmlfile            =   UniDokkan::Dokkan::cocos2d_UserDefault_getInstance();
  36.     UD_LOGI("Language detection : let check language");
  37.     if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, label_ja)) {
  38.         if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, label_fr)) {
  39.             UD_LOGI("Language detection : FR Patch found");
  40.             return "frja";
  41.         } else if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, label_en)) {
  42.             UD_LOGI("Language detection : Japan client with english patch");
  43.             return "enja";
  44.         } else {
  45.             UD_LOGI("Language detection : Japan client without english patch");
  46.             return "ja"; //<- default.
  47.         }
  48.     } else {
  49.         auto getStringForKey    =   DokkanFunction<std::string(void *,const char *)>("_ZN7cocos2d11UserDefault15getStringForKeyEPKc");
  50.         auto glblanguage = getStringForKey(xmlfile, "CurrentUsingLanguage");
  51.         UD_LOGI("Language detection : %s", glblanguage.c_str());
  52.         return glblanguage;
  53.     }
  54. }
  55. bool(*ori__turncounter_scene_1)(void *)= nullptr;
  56. bool turncounter_scene_1(void *self) {
  57.     UD_LOGI("turncounter_scene_1 Init"); //Crash 1 : this appear
  58.    
  59.     auto res = ori__turncounter_scene_1(self); // <- Crash here if I do not comment whole res and if
  60.     if (!res) {
  61.         UD_LOGE("auto res = ori__turncounter_scene_1(self); failed!");
  62.         return res;
  63.     }
  64.    
  65.     UD_LOGI("ori__turncounter_scene_1");
  66.     auto screen_size = cocos2d_Director_getVisibleSize(UniDokkan::Dokkan::cocos2d_Director_getInstance());
  67.    
  68.     UD_LOGI("turncounter_scene_1 Setup");
  69.     auto OriW           =   screen_size.width;
  70.     auto OriH           =   screen_size.height;
  71.     float Ypos          =   OriH/2;
  72.     float XPos          =   OriW/2;
  73.     float Y_Pos_Text    =   Ypos + Pos_Y_Text;
  74.     float X_Pos_Text    =   XPos + Pos_X_Text;
  75.     float Y_Pos_Num     =   Ypos + Pos_Y_Number;
  76.     float X_Pos_Num     =   XPos + Pos_X_Number;
  77.  
  78.     auto Lang           =   DetectLanguage();
  79.     if (Lang == "en" || Lang == "enja") {
  80.         Label_Turn  =   "Turn N.";
  81.         if (Lang == "en") {
  82.             BasePath    =   "fonts/fonts/en/custom";
  83.         } else {
  84.             BasePath    =   "fonts/ja/custom/"; //Need to fix not actually going there
  85.         }
  86.     } else if (Lang == "fr" || Lang == "frja") {
  87.         Label_Turn  =   "Tour N.";
  88.         if (Lang == "en") {
  89.             BasePath    =   "fonts/fonts/fr/custom";
  90.         } else {
  91.             BasePath    =   "fonts/ja/custom/"; //Need to fix not actually going there
  92.         }
  93.     } else if (Lang == "zh") {
  94.         Label_Turn  =   "轉 ";
  95.         BasePath    =   "fonts/fonts/zh/custom";
  96.     } else if (Lang == "ko") {
  97.         Label_Turn  =   "회전 ";
  98.         BasePath    =   "fonts/fonts/ko/custom";
  99.     } else if (Lang == "ja") {
  100.         Label_Turn  =   "順番 ";
  101.         BasePath    =   "fonts/ja/custom/";
  102.     } else {
  103.         Label_Turn  =   "順番 ";
  104.         BasePath    =   "fonts/ja/custom/";
  105.     }
  106.  
  107.     std::string Path_Text       = BasePath + Font_text + "/" + Font_text + ".fnt";
  108.     std::string Path_Numbers    = BasePath + Font_number + "/" + Font_number + ".fnt";
  109.    
  110.     //Will hold turn label
  111.     UD_LOGI("Turn_Label Setup"); //Crash 2 : this appear
  112.     auto Turn_Label = new Label("Label_turn", self, 100); // <- Crash 2 : here if I  comment whole res and if at line 60
  113.     Turn_Label->setBMFont(Path_Text, Text_Size);
  114.     Turn_Label->setCaption(Label_Turn);
  115.     Turn_Label->setAlignment(cocos2d::TextHAlignment::CENTER, cocos2d::TextVAlignment::CENTER);
  116.     Turn_Label->setSize(200, 75);
  117.     Turn_Label->setAnchorPoint(Node::AnchorTopRight);
  118.     Turn_Label->setPosition({X_Pos_Text, Y_Pos_Text});
  119.    
  120.     //Will hold turn count
  121.     UD_LOGI("Turn_counter Setup");
  122.     auto Turn_counter = new Label("Label_turncounter", self, 100);
  123.     Turn_counter->setBMFont(Path_Numbers, Text_Size+5.0f);
  124.     Turn_counter->setCaption("9999");
  125.     Turn_counter->setAlignment(cocos2d::TextHAlignment::LEFT, cocos2d::TextVAlignment::CENTER);
  126.     Turn_counter->setSize(200, 75);
  127.     Turn_counter->setAnchorPoint(Node::AnchorTopLeft);
  128.     Turn_counter->setPosition({X_Pos_Num, Y_Pos_Num});
  129.     return true;
  130. }
  131.  
  132. extern "C" {
  133.     __attribute__ ((visibility ("default")))
  134.     int unidokkan_init_v3(HookLibV3 *hook_lib) {
  135.         UD_LOGI("turncounter custom module loading...");
  136.  
  137.         if (hook_lib->size < sizeof(HookLibV3)) {
  138.             return UD_MODULE_INVALID_SIZE;
  139.         }
  140.  
  141.         if (hook_lib->version < kMinPatcherVer) {
  142.             return UD_MODULE_INVALID_VERSION;
  143.         }
  144.  
  145.         auto res = hook_lib->applyHooks({
  146.             //Work
  147.             {DOKKAN_LIB, "_ZN18CharacterMenuScene4initEv", reinterpret_cast<void *>(turncounter_scene_1), reinterpret_cast<void **>(&ori__turncounter_scene_1)}
  148.             //Crash
  149.             // {DOKKAN_LIB, "_ZN16InGameFooterView4initEv", reinterpret_cast<void *>(turncounter_scene_1), reinterpret_cast<void **>(&ori__turncounter_scene_1)}
  150.         });
  151.        
  152.         if (!res) {
  153.             return UD_MODULE_ERROR;
  154.         }
  155.  
  156.         UD_LOGI("turncounter loaded.");
  157.         return UD_MODULE_SUCCESS;
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment