Baoulettes

Untitled

Jun 13th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.72 KB | None | 0 0
  1. #include <unidokkan/log.h>
  2. #include <unidokkan/hook.h>
  3. #include <cocos/base/ccTypes.h>
  4. #include <cocos/ui/UIWidget.h>
  5. #include <cocos/2d/CCProgressTimer.h>
  6. #include <cocos/ui/UILayout.h>
  7. #include <cocos/base/CCDirector.h>
  8. #include <cocos/2d/CCLabel.h>
  9. #include <unidokkan/errors.h>
  10. #include <tuple>
  11.  
  12. auto setKerning = DokkanFunction<void *(void *, float)>("_ZN7cocos2d5Label20setAdditionalKerningEf");
  13. auto getKerning = DokkanFunction<float(void *)>("_ZNK7cocos2d5Label20getAdditionalKerningEv");
  14. auto getVirtualRenderer = DokkanFunction<void *(void *)>("_ZN7cocos2d2ui4Text18getVirtualRendererEv");
  15. auto getVirtualRendererBM = DokkanFunction<void *(void *)>("_ZN7cocos2d2ui10TextBMFont18getVirtualRendererEv");
  16. auto getDescription = DokkanFunction<std::string (void *)>("_ZNK7cocos2d2ui10TextBMFont14getDescriptionEv");
  17. auto getBMFontSize = DokkanFunction<float (void *)>("_ZNK7cocos2d5Label13getBMFontSizeEv");
  18. auto setLineBreakNoSpace = DokkanFunction<void *(void *, bool)>("_ZN7cocos2d5Label24setLineBreakWithoutSpaceEb");
  19. auto setLineSpacing = DokkanFunction<void *(void *, float)>("_ZN7cocos2d5Label14setLineSpacingEf");
  20. auto setFontSizeBmFont = DokkanFunction<void *(void *, float)>("_ZN7cocos2d5Label13setBMFontSizeEf");
  21. auto setLineHeight = DokkanFunction<void *(void *, float)>("_ZN7cocos2d5Label13setLineHeightEf");
  22.  
  23. bool Debug = false;
  24.  
  25. void (*ori__cocos2d2ui4Text_generic)(void *, std::string) = nullptr;
  26. void cocos2d2ui4Text_generic(void *self, std::string string) {
  27. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : called"); }
  28. auto Description = getDescription(self);
  29. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : %s", Description.c_str()); }
  30. if (Description != "TextBMFont") {
  31. auto labelRenderer = getVirtualRenderer(self);
  32. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : getKerning"); }
  33. static float getKerning = getKerning(labelRenderer);
  34. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : %f", getKerning); }
  35. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : setKerning"); }
  36. static float getKerning = getKerning/2;
  37. setKerning(labelRenderer, getKerning);
  38. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : %f", getKerning); }
  39. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : Finishing !"); }
  40. } else {
  41. auto labelRenderer = getVirtualRenderer(self);
  42. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : TextBMFont : getKerning"); }
  43. static float getKerning = getKerning(labelRenderer);
  44. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : TextBMFont : %f", getKerning); }
  45. if (getKerning != BMKerning) {
  46. static float getKerning = getKerning/4;
  47. setKerning(labelRenderer, getKerning);
  48. if (Debug == true) { UD_LOGI("cocos2d2ui4Text_generic : TextBMFont : %f", getKerning); }
  49. }
  50. ori__cocos2d2ui4Text_generic(self, string);
  51. }
  52. }
  53. void (*ori__setBMFontSize_generic)(void *, const std::string &, const ud_cocos2d::Vec2 &, float) = nullptr;
  54. void setBMFontSize_generic(void *self, const std::string &fntfile, const ud_cocos2d::Vec2 &unk, float unk2) {
  55. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : called"); }
  56. ori__setBMFontSize_generic(self,fntfile,unk,unk2);
  57. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : getDescription"); }
  58. auto Description = getDescription(self);
  59. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : %s", Description.c_str()); }
  60. if (Description == "TextBMFont") {
  61. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : Thie is a TextBMFont let continue !"); }
  62. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : %s", fntfile.c_str()); }
  63. if (fntfile == "fonts/ja/custom/btn_normal/btn_normal.fnt") {
  64. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : Thie is a btn_normal let continue !"); }
  65. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : getVirtualRendererBM"); }
  66. auto labelRendererBM = getVirtualRendererBM(self);
  67. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : getBMFontSize"); }
  68. static float Font_size = getBMFontSize(labelRendererBM);
  69. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : Calculate new Fontsize"); }
  70. static float FontSizeBmFont = (Font_size*100)/115;
  71. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : setBMFontSize"); }
  72. setFontSizeBmFont(labelRendererBM, FontSizeBmFont);
  73. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : setLineBreakNoSpace"); }
  74. setLineBreakNoSpace(labelRendererBM, true);
  75. float LineSpacing = (Font_size * 1.8) - FontSizeBmFont;
  76. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : setLineSpacing"); }
  77. setLineSpacing(labelRendererBM, -10.0f);
  78. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : setLineHeight"); }
  79. float LineHeight = FontSizeBmFont * 2.6;
  80. setLineHeight(labelRendererBM, LineHeight);
  81. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : setKerning"); }
  82. setKerning(labelRendererBM, BMKerning);
  83. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : Finishing [btn_normal]!"); }
  84. } else {
  85. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : Thie is not a btn_normal !"); }
  86. }
  87. } else {
  88. if (Debug == true) { UD_LOGI("setup_Label_BMFont_generic : Thie is not a TextBMFont!"); }
  89. }
  90. }
  91. void (*ori__setAdditionalKerning_generic)(void *, float) = nullptr;
  92. void setAdditionalKerning_generic(void *self, float passed_kerning) {
  93. UD_LOGI("setAdditionalKerning_generic : called");
  94. UD_LOGI("setAdditionalKerning_generic : size is : %f", passed_kerning);
  95. UD_LOGI("setAdditionalKerning_generic : BMKerning is: %f", BMKerning);
  96. if (passed_kerning != BMKerning) {
  97. passed_kerning = 100.0f;
  98. }
  99. UD_LOGI("setAdditionalKerning_generic : newvalue is : %f", passed_kerning);
  100. ori__setAdditionalKerning_generic(self, passed_kerning);
  101. }
  102. void (*ori__setLineSpacing_generic)(void *, float) = nullptr;
  103. void setLineSpacing_generic(void *self, float LineSpacing) {
  104. if (Debug == true) { UD_LOGI("setLineSpacing_generic : called"); }
  105. auto Description = getDescription(self);
  106. if (Debug == true) { UD_LOGI("setLineSpacing_generic : %s", Description.c_str()); }
  107. if (LineSpacing != -10.0f) {
  108. LineSpacing = 0.0f;
  109. }
  110. ori__setLineSpacing_generic(self, LineSpacing);
  111. }
  112. void (*ori__enableOutline_generic)(void *, ud_cocos2d::Color4B &, int) = nullptr;
  113. void enableOutline_generic(void *self, ud_cocos2d::Color4B &outlineColor, int outlineSize) {
  114. if (Debug == true) { UD_LOGI("enableOutline_generic : called"); }
  115. if (Debug == true) { UD_LOGI("enableOutline_generic : size is : %d", outlineSize); }
  116. if (outlineSize >= 2) { outlineSize = outlineSize/2; }
  117. if (Debug == true) { UD_LOGI("enableOutline_generic : newvalue is : %d", outlineSize); }
  118. ori__enableOutline_generic(self, outlineColor, outlineSize);
  119. }
  120. extern "C" {
  121. [[maybe_unused]] __attribute__ ((visibility ("default")))
  122. int unidokkan_init_v4(HookLibV4* hook_lib) {
  123. UD_LOGI("English Buttons module loading...");
  124. if (hook_lib->size < sizeof(HookLibV4)) {
  125. return UD_MODULE_INVALID_SIZE;
  126. }
  127. if (hook_lib->version < kMinPatcherVer) {
  128. return UD_MODULE_INVALID_VERSION;
  129. }
  130. auto res = hook_lib->applyHooks(
  131. {
  132. {DOKKAN_LIB, "_ZN7cocos2d2ui4Text9setStringERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE", cocos2d2ui4Text_generic, &ori__cocos2d2ui4Text_generic},
  133. {DOKKAN_LIB, "_ZN7cocos2d5Label13enableOutlineERKNS_7Color4BEi", enableOutline_generic, &ori__enableOutline_generic},
  134. {DOKKAN_LIB, "_ZN7cocos2d5Label14setLineSpacingEf", setLineSpacing_generic, &ori__setLineSpacing_generic},
  135. {DOKKAN_LIB, "_ZN7cocos2d2ui10TextBMFont10setFntFileERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE", setBMFontSize_generic, &ori__setBMFontSize_generic},
  136. }
  137. );
  138. if (!res) {
  139. return UD_MODULE_ERROR;
  140. }
  141.  
  142. UD_LOGI("English Buttons successfully loaded.");
  143. return UD_MODULE_SUCCESS;
  144. }
  145. }
Add Comment
Please, Sign In to add comment