Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fmt/format.h>
- #include <unidokkan/errors.h>
- #include <unidokkan/hook.h>
- #include <dokkan/files.h>
- #include <dokkan/instances.h>
- #include <unidokkan/ui/defs.h>
- #include <unidokkan/ui/label.h>
- #include <unidokkan/ui/scene.h>
- #include <unidokkan/ui/button.h>
- #include <unidokkan/ui/layout.h>
- #include <unidokkan/ui/imageview.h>
- #include <unidokkan/ui/progresstimer.h>
- #include <cocos/ui/UIButton.h>
- #include <cocos/base/CCDirector.h>
- #include <cocos/2d/CCActionInterval.h>
- #include <unidokkan/database.h>
- #include <string>
- using namespace UniDokkan::UI;
- namespace cocos2d = ud_cocos2d;
- std::string BasePath;
- std::string Label_Turn;
- std::string Font_text = "btn_normal";
- std::string Font_number = "gold_text";
- float Text_Size = 10.0f;
- float Pos_X_Text = 0.0f;
- float Pos_Y_Text = 0.0f;
- float Pos_X_Number = 0.0f;
- float Pos_Y_Number = 0.0f;
- std::string label_ja = "sqlite/current/database.db";
- std::string label_fr = "french.txt";
- std::string label_en = "english.txt";
- std::string DetectLanguage(){
- UD_LOGI("Language detection : init");
- auto file_utils = UniDokkan::Dokkan::cocos2d_FileUtils_getInstance();
- auto xmlfile = UniDokkan::Dokkan::cocos2d_UserDefault_getInstance();
- UD_LOGI("Language detection : let check language");
- if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, label_ja)) {
- if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, label_fr)) {
- UD_LOGI("Language detection : FR Patch found");
- return "frja";
- } else if (UniDokkan::Dokkan::cocos2d_FileUtils_isFileExistWithoutCpk(file_utils, label_en)) {
- UD_LOGI("Language detection : Japan client with english patch");
- return "enja";
- } else {
- UD_LOGI("Language detection : Japan client without english patch");
- return "ja"; //<- default.
- }
- } else {
- auto getStringForKey = DokkanFunction<std::string(void *,const char *)>("_ZN7cocos2d11UserDefault15getStringForKeyEPKc");
- auto glblanguage = getStringForKey(xmlfile, "CurrentUsingLanguage");
- UD_LOGI("Language detection : %s", glblanguage.c_str());
- return glblanguage;
- }
- }
- bool(*ori__turncounter_scene_1)(void *)= nullptr;
- bool turncounter_scene_1(void *self) {
- UD_LOGI("turncounter_scene_1 Init"); //Crash 1 : this appear
- auto res = ori__turncounter_scene_1(self); // <- Crash here if I do not comment whole res and if
- if (!res) {
- UD_LOGE("auto res = ori__turncounter_scene_1(self); failed!");
- return res;
- }
- UD_LOGI("ori__turncounter_scene_1");
- auto screen_size = cocos2d_Director_getVisibleSize(UniDokkan::Dokkan::cocos2d_Director_getInstance());
- UD_LOGI("turncounter_scene_1 Setup");
- auto OriW = screen_size.width;
- auto OriH = screen_size.height;
- float Ypos = OriH/2;
- float XPos = OriW/2;
- float Y_Pos_Text = Ypos + Pos_Y_Text;
- float X_Pos_Text = XPos + Pos_X_Text;
- float Y_Pos_Num = Ypos + Pos_Y_Number;
- float X_Pos_Num = XPos + Pos_X_Number;
- auto Lang = DetectLanguage();
- if (Lang == "en" || Lang == "enja") {
- Label_Turn = "Turn N.";
- if (Lang == "en") {
- BasePath = "fonts/fonts/en/custom";
- } else {
- BasePath = "fonts/ja/custom/"; //Need to fix not actually going there
- }
- } else if (Lang == "fr" || Lang == "frja") {
- Label_Turn = "Tour N.";
- if (Lang == "en") {
- BasePath = "fonts/fonts/fr/custom";
- } else {
- BasePath = "fonts/ja/custom/"; //Need to fix not actually going there
- }
- } else if (Lang == "zh") {
- Label_Turn = "轉 ";
- BasePath = "fonts/fonts/zh/custom";
- } else if (Lang == "ko") {
- Label_Turn = "회전 ";
- BasePath = "fonts/fonts/ko/custom";
- } else if (Lang == "ja") {
- Label_Turn = "順番 ";
- BasePath = "fonts/ja/custom/";
- } else {
- Label_Turn = "順番 ";
- BasePath = "fonts/ja/custom/";
- }
- std::string Path_Text = BasePath + Font_text + "/" + Font_text + ".fnt";
- std::string Path_Numbers = BasePath + Font_number + "/" + Font_number + ".fnt";
- //Will hold turn label
- UD_LOGI("Turn_Label Setup"); //Crash 2 : this appear
- auto Turn_Label = new Label("Label_turn", self, 100); // <- Crash 2 : here if I comment whole res and if at line 60
- Turn_Label->setBMFont(Path_Text, Text_Size);
- Turn_Label->setCaption(Label_Turn);
- Turn_Label->setAlignment(cocos2d::TextHAlignment::CENTER, cocos2d::TextVAlignment::CENTER);
- Turn_Label->setSize(200, 75);
- Turn_Label->setAnchorPoint(Node::AnchorTopRight);
- Turn_Label->setPosition({X_Pos_Text, Y_Pos_Text});
- //Will hold turn count
- UD_LOGI("Turn_counter Setup");
- auto Turn_counter = new Label("Label_turncounter", self, 100);
- Turn_counter->setBMFont(Path_Numbers, Text_Size+5.0f);
- Turn_counter->setCaption("9999");
- Turn_counter->setAlignment(cocos2d::TextHAlignment::LEFT, cocos2d::TextVAlignment::CENTER);
- Turn_counter->setSize(200, 75);
- Turn_counter->setAnchorPoint(Node::AnchorTopLeft);
- Turn_counter->setPosition({X_Pos_Num, Y_Pos_Num});
- return true;
- }
- extern "C" {
- __attribute__ ((visibility ("default")))
- int unidokkan_init_v3(HookLibV3 *hook_lib) {
- UD_LOGI("turncounter custom module loading...");
- if (hook_lib->size < sizeof(HookLibV3)) {
- return UD_MODULE_INVALID_SIZE;
- }
- if (hook_lib->version < kMinPatcherVer) {
- return UD_MODULE_INVALID_VERSION;
- }
- auto res = hook_lib->applyHooks({
- //Work
- {DOKKAN_LIB, "_ZN18CharacterMenuScene4initEv", reinterpret_cast<void *>(turncounter_scene_1), reinterpret_cast<void **>(&ori__turncounter_scene_1)}
- //Crash
- // {DOKKAN_LIB, "_ZN16InGameFooterView4initEv", reinterpret_cast<void *>(turncounter_scene_1), reinterpret_cast<void **>(&ori__turncounter_scene_1)}
- });
- if (!res) {
- return UD_MODULE_ERROR;
- }
- UD_LOGI("turncounter loaded.");
- return UD_MODULE_SUCCESS;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment