xmake.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package("bnm-android")
  2. set_homepage("https://github.com/ByNameModding/BNM-Android")
  3. set_description("Modding il2cpp games by classes, methods, fields names on Android.")
  4. add_urls("https://github.com/ByNameModding/BNM-Android.git")
  5. add_versions("2025.10.14", "502928771983d29e37f28c78f28823dfb775a3aa")
  6. add_configs("link_log", {description = "Link against liblog.so", default = false, type = "boolean"})
  7. add_configs("hook_lib", {
  8. description = "Choose the hooking library used (dobby or shadowhook).",
  9. default = "shadowhook",
  10. type = "string",
  11. values = {"shadowhook", "dobby"},
  12. })
  13. add_configs("unity_version", {
  14. description = "Unity version (e.g., 5.6.4, 2017.1.0, 2022.2.1)",
  15. default = "2022.2.0",
  16. type = "string",
  17. })
  18. on_load(function (package)
  19. package:add("deps", package:config("hook_lib"))
  20. end)
  21. local parse_unity_version = function (version)
  22. local major, minor, patch = version:match("^(%d+)%.(%d+)%.(%d+)")
  23. if not major then
  24. major, minor = version:match("^(%d+)%.(%d+)%.%w+")
  25. if not major then
  26. return 222, 32
  27. end
  28. patch = nil
  29. end
  30. major = tonumber(major)
  31. minor = tonumber(minor)
  32. patch = patch and tonumber(patch) or nil
  33. local unity_ver
  34. local unity_patch_ver
  35. if major == 5 then
  36. if minor == 6 then
  37. unity_ver = 56
  38. end
  39. elseif major == 2017 then
  40. if minor == 1 then
  41. unity_ver = 171
  42. elseif minor >= 2 and minor <= 4 then
  43. unity_ver = 172
  44. end
  45. elseif major == 2018 then
  46. if minor == 1 then
  47. unity_ver = 181
  48. elseif minor == 2 then
  49. unity_ver = 182
  50. elseif minor >= 3 then
  51. unity_ver = 183
  52. end
  53. elseif major == 2019 then
  54. if minor <= 2 then
  55. unity_ver = 191
  56. elseif minor == 3 then
  57. unity_ver = 193
  58. elseif minor == 4 then
  59. unity_ver = 194
  60. end
  61. elseif major == 2020 then
  62. if minor == 1 then
  63. unity_ver = 201
  64. elseif minor == 2 then
  65. unity_ver = 202
  66. elseif minor == 3 then
  67. if patch and patch >= 20 then
  68. unity_ver = 203
  69. else
  70. unity_ver = 202
  71. end
  72. end
  73. elseif major == 2021 then
  74. if minor == 1 then
  75. unity_ver = 211
  76. -- Need to set UNITY_PATCH_VER to 24 if x (2021.1.x) >= 24
  77. if patch and patch >= 24 then
  78. unity_patch_ver = patch
  79. end
  80. elseif minor == 2 then
  81. unity_ver = 212
  82. elseif minor == 3 then
  83. unity_ver = 213
  84. end
  85. elseif major == 2022 then
  86. if minor == 1 then
  87. unity_ver = 221
  88. elseif minor >= 2 then
  89. unity_ver = 222
  90. unity_patch_ver = patch or 32
  91. end
  92. elseif major == 2023 then
  93. if minor == 1 then
  94. unity_ver = 231
  95. elseif minor >= 2 then
  96. unity_ver = 232
  97. end
  98. end
  99. -- Fallback to default if no match found
  100. if not unity_ver then
  101. unity_ver = 222
  102. unity_patch_ver = 32
  103. end
  104. return unity_ver, unity_patch_ver
  105. end
  106. on_install("android", function (package)
  107. local unity_version = package:config("unity_version")
  108. local unity_ver, unity_patch_ver = parse_unity_version(unity_version)
  109. local dummy_impl = [[// Dummy
  110. #include <cassert>
  111. static_assert(false, "No hooking software!");
  112. template<typename PTR_T, typename NEW_T, typename T_OLD>
  113. inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &oldBytes) {
  114. if ((void *) ptr != nullptr) ((void)0);
  115. return nullptr;
  116. }
  117. template<typename PTR_T, typename NEW_T, typename T_OLD>
  118. inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &&oldBytes) {
  119. if ((void *) ptr != nullptr) ((void)0);
  120. return nullptr;
  121. }
  122. template<typename PTR_T>
  123. inline void Unhook(PTR_T ptr) {
  124. if ((void *) ptr != nullptr) ((void)0);
  125. }
  126. ]]
  127. io.replace("include/BNM/UserSettings/GlobalSettings.hpp", "#define UNITY_VER 222 // 2022.2.x", "#define UNITY_VER " .. unity_ver .. " // " .. unity_version, {plain = true})
  128. if unity_patch_ver then
  129. io.replace("include/BNM/UserSettings/GlobalSettings.hpp", "#define UNITY_PATCH_VER 32", "#define UNITY_PATCH_VER " .. unity_patch_ver, {plain = true})
  130. end
  131. if package:config("hook_lib") == "dobby" then
  132. io.replace("include/BNM/UserSettings/GlobalSettings.hpp", dummy_impl, [[
  133. #include <dobby.h>
  134. template<typename PTR_T, typename NEW_T, typename T_OLD>
  135. inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &oldBytes) {
  136. if ((void *) ptr != nullptr) DobbyHook((void *)ptr, (void *) newMethod, (void **) &oldBytes);
  137. return (void *) ptr;
  138. }
  139. template<typename PTR_T, typename NEW_T, typename T_OLD>
  140. inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &&oldBytes) {
  141. if ((void *) ptr != nullptr) DobbyHook((void *)ptr, (void *) newMethod, (void **) &oldBytes);
  142. return (void *) ptr;
  143. }
  144. template<typename PTR_T>
  145. inline void Unhook(PTR_T ptr) {
  146. if ((void *) ptr != nullptr) DobbyDestroy((void *)ptr);
  147. }
  148. ]], {plain = true})
  149. elseif package:config("hook_lib") == "shadowhook" then
  150. io.replace("include/BNM/UserSettings/GlobalSettings.hpp", dummy_impl, [[
  151. #include "shadowhook.h"
  152. template<typename PTR_T, typename NEW_T, typename T_OLD>
  153. inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &oldBytes) {
  154. if ((void *) ptr != nullptr) return shadowhook_hook_func_addr((void *)ptr, (void *) newMethod, (void **) &oldBytes);
  155. return nullptr;
  156. }
  157. template<typename PTR_T, typename NEW_T, typename T_OLD>
  158. inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &&oldBytes) {
  159. if ((void *) ptr != nullptr) return shadowhook_hook_func_addr((void *)ptr, (void *) newMethod, (void **) &oldBytes);
  160. return nullptr;
  161. }
  162. template<typename PTR_T>
  163. inline void Unhook(PTR_T ptr) {
  164. if ((void *) ptr != nullptr) shadowhook_unhook((void *)ptr);
  165. }
  166. ]], {plain = true})
  167. else
  168. raise("Unknown hooking library: " .. package:config("hook_lib"))
  169. end
  170. io.replace("include/BNM/UnityStructures/Matrix4x4.hpp", [[#include "Matrix3x3.hpp"]], [[#include "Matrix3x3.hpp"
  171. #include <cmath>]], {plain = true})
  172. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  173. import("package.tools.xmake").install(package, {
  174. link_log = package:config("link_log"),
  175. hook_lib = package:config("hook_lib"),
  176. unity_version = package:config("unity_version"),
  177. version = package:version_str()
  178. })
  179. end)
  180. on_test(function (package)
  181. package:check_cxxsnippets({test = [[
  182. void test() {
  183. BNM::Loading::TryLoadByUsersFinder();
  184. }
  185. ]]}, {configs = {languages = "c++20"}, includes = {"BNM/Loading.hpp"}})
  186. end)